diff --git a/src/main/java/com/primefactorsolutions/service/EmployeeService.java b/src/main/java/com/primefactorsolutions/service/EmployeeService.java index 76f9521..716827d 100644 --- a/src/main/java/com/primefactorsolutions/service/EmployeeService.java +++ b/src/main/java/com/primefactorsolutions/service/EmployeeService.java @@ -1,5 +1,6 @@ package com.primefactorsolutions.service; +import com.primefactorsolutions.model.Candidate; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.repositories.EmployeeRepository; import lombok.Data; @@ -18,8 +19,9 @@ public class EmployeeService { this.employeeRepository = employeeRepository; } - public Employee createOrUpdate(final Employee assessment) { - return null; + public Employee createOrUpdate(final Employee employee) { + final Employee saved = employeeRepository.save(employee); + return saved; } public List getEmployees() { diff --git a/src/main/java/com/primefactorsolutions/views/EmployeeView.java b/src/main/java/com/primefactorsolutions/views/EmployeeView.java index 5f5acf8..6003b76 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeeView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeeView.java @@ -3,16 +3,20 @@ package com.primefactorsolutions.views; import com.primefactorsolutions.model.Employee; import com.primefactorsolutions.service.EmployeeService; import com.vaadin.flow.component.Component; +import com.vaadin.flow.component.textfield.EmailField; +import com.vaadin.flow.component.textfield.TextField; import com.vaadin.flow.router.BeforeEvent; import com.vaadin.flow.router.HasUrlParameter; import com.vaadin.flow.router.PageTitle; import com.vaadin.flow.router.Route; import com.vaadin.flow.spring.annotation.SpringComponent; import jakarta.annotation.security.PermitAll; +import org.apache.commons.lang3.StringUtils; import org.springframework.context.annotation.Scope; import org.vaadin.firitin.form.BeanValidationForm; import java.util.List; +import java.util.UUID; @SpringComponent @PermitAll @@ -20,22 +24,36 @@ import java.util.List; @PageTitle("Employee") @Route(value = "/employees", layout = MainLayout.class) public class EmployeeView extends BeanValidationForm implements HasUrlParameter { - private final EmployeeService employeeService; + private TextField name = null; + public EmployeeView(final EmployeeService employeeService) { super(Employee.class); this.employeeService = employeeService; - } + name = new TextField(); + name.setWidthFull(); + name.setLabel("Name"); - @Override - protected List getFormComponents() { - return null; + setSavedHandler((SavedHandler) employee -> { + final Employee saved = employeeService.createOrUpdate(employee); + setEntityWithEnabledSave(saved); + }); } @Override public void setParameter(final BeforeEvent beforeEvent, final String s) { + if (StringUtils.isNotBlank(s) && !"new".equals(s)) { + var employee = employeeService.getEmployee(UUID.fromString(s)); + setEntityWithEnabledSave(employee); + } else { + setEntityWithEnabledSave(new Employee()); + } + } + @Override + protected List getFormComponents() { + return List.of(name); } } diff --git a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java index 1e13d4c..145ff28 100644 --- a/src/main/java/com/primefactorsolutions/views/EmployeesListView.java +++ b/src/main/java/com/primefactorsolutions/views/EmployeesListView.java @@ -117,7 +117,7 @@ public class EmployeesListView extends Main { hf.add(next); final Button addEmployee = new Button("Add Employee"); addEmployee.addClickListener((ComponentEventListener>) buttonClickEvent -> { - //this.getUI().get().navigate(EmployeeView.class, "new"); + this.getUI().get().navigate(EmployeeView.class, "new"); }); hf.add(addEmployee);