diff --git a/data.mv.db b/data.mv.db index 62d5725..f3f9216 100644 Binary files a/data.mv.db and b/data.mv.db differ diff --git a/src/main/java/com/example/demo/speaker/controller/DTO/EmployeeDTO.java b/src/main/java/com/example/demo/speaker/controller/DTO/EmployeeDTO.java index 8e06742..13e8a1b 100644 --- a/src/main/java/com/example/demo/speaker/controller/DTO/EmployeeDTO.java +++ b/src/main/java/com/example/demo/speaker/controller/DTO/EmployeeDTO.java @@ -21,9 +21,7 @@ public class EmployeeDTO { public String getFio() { return fio; } - public void setAppointment(Long appointment) { - this.appointmentId = appointment; - } + public void setAppointmentId(Long appointment) { this.appointmentId = appointment; } public void setFio(String fio) { this.fio = fio; diff --git a/src/main/java/com/example/demo/speaker/controller/DTO/RequestForCooperationDTO.java b/src/main/java/com/example/demo/speaker/controller/DTO/RequestForCooperationDTO.java index 273bd29..c0f83b3 100644 --- a/src/main/java/com/example/demo/speaker/controller/DTO/RequestForCooperationDTO.java +++ b/src/main/java/com/example/demo/speaker/controller/DTO/RequestForCooperationDTO.java @@ -8,39 +8,39 @@ import java.util.Date; public class RequestForCooperationDTO { private Long id; - private Company nameCompany; + private Long nameCompany; private String comment; private Date createDate; private Date approveDate; private Boolean isActive; - private EmployeeDTO sotr; + private Long sotr; private TypeOfRequestEnum type; public RequestForCooperationDTO(RequestForCooperation request) { this.id = request.getId(); - this.nameCompany = request.getName(); + this.nameCompany = request.getName().getId(); this.comment = request.getComment(); this.approveDate = request.getApproveDate(); - this.sotr = new EmployeeDTO(request.getWorker()); + this.sotr = request.getWorker().getId(); this.createDate = request.getCreateDate(); this.isActive = request.getActive(); this.type = request.getType(); } - +public RequestForCooperationDTO(){} public long getId() { return this.id; } public String getComment() { return comment; } public Boolean getActive() { return isActive; } - public Company getNameCompany() { return nameCompany; } + public Long getNameCompany() { return nameCompany; } public Date getApproveDate() { return approveDate; } public Date getCreateDate() { return createDate; } - public EmployeeDTO getSotr() { return sotr; } + public Long getSotr() { return sotr; } public TypeOfRequestEnum getType() {return type; } @@ -60,11 +60,11 @@ public class RequestForCooperationDTO { this.createDate = createDate; } - public void setNameCompany(Company nameCompany) { + public void setNameCompany(Long nameCompany) { this.nameCompany = nameCompany; } - public void setSotr(EmployeeDTO sotr) { + public void setSotr(Long sotr) { this.sotr = sotr; } diff --git a/src/main/java/com/example/demo/speaker/controller/MVCController/EmployeeMVCController.java b/src/main/java/com/example/demo/speaker/controller/MVCController/EmployeeMVCController.java index 353f8f6..c3c690c 100644 --- a/src/main/java/com/example/demo/speaker/controller/MVCController/EmployeeMVCController.java +++ b/src/main/java/com/example/demo/speaker/controller/MVCController/EmployeeMVCController.java @@ -44,7 +44,7 @@ public class EmployeeMVCController { @PostMapping("/create") public String createWorker(@ModelAttribute EmployeeDTO employeeDTO, Model model) { employeeService.addWorker(employeeDTO); - return "redirect:employee"; + return "employee"; } @PostMapping("/edit/{id}") @@ -52,7 +52,7 @@ public class EmployeeMVCController { employeeService.updateReportWorker(id, employeeDTO); // model.addAttribute("employees", employeeService.findAllWorkers()); // model.addAttribute("appointments", appointmentService.findAllAppointments()); - return "redirect:employee"; + return "/employee"; } @PostMapping("/delete/{id}") diff --git a/src/main/java/com/example/demo/speaker/controller/MVCController/RequestMVCController.java b/src/main/java/com/example/demo/speaker/controller/MVCController/RequestMVCController.java index 6d98f01..feaf369 100644 --- a/src/main/java/com/example/demo/speaker/controller/MVCController/RequestMVCController.java +++ b/src/main/java/com/example/demo/speaker/controller/MVCController/RequestMVCController.java @@ -10,10 +10,12 @@ import com.example.demo.speaker.model.TypeOfRequestEnum; import com.example.demo.speaker.service.CompanyService; import com.example.demo.speaker.service.EmployeeService; import com.example.demo.speaker.service.RequestForCooperationService; +import org.h2.store.Data; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; +import java.time.LocalDateTime; import java.util.Date; import java.util.List; @@ -39,6 +41,7 @@ public class RequestMVCController { @GetMapping public String getRequests(Model model) { + model.addAttribute("requestDTO", new RequestForCooperationDTO()); model.addAttribute("requests", requestForCooperationService.findAllRequests() .stream().map(RequestForCooperationDTO::new).toList()); model.addAttribute("types", types); @@ -49,27 +52,23 @@ public class RequestMVCController { return "request"; } - @PostMapping("/add") - public String createRequest(@PathVariable Long nameCompany, - @PathVariable String comment, - @PathVariable Integer isActive, - @PathVariable Long sort, - @PathVariable Long type, + @PostMapping("/create") + public String createRequest(@ModelAttribute("requestDTO") RequestForCooperationDTO requestDTO, Model model ){ - + requestDTO.setCreateDate(new Date()); + requestDTO.setApproveDate(new Date()); //@RequestBody RequestForCooperationDTO requestDTO) { - var company = companyService.findCompany(nameCompany); - var emp = employeeService.findWorker(sort); - var request = new RequestForCooperation(company, new Date(), type == 0 ? TypeOfRequestEnum.DEVELOP : TypeOfRequestEnum.TRACKING, comment); - requestForCooperationService.addRequest(new RequestForCooperationDTO(request)); - return "redirect:request"; + requestForCooperationService.addRequest(requestDTO); + return "request"; } @PutMapping("/{id}") public String updateRequest(@PathVariable Long id, @ModelAttribute RequestForCooperationDTO request, Model model) { + request.setApproveDate(new Date()); + request.setCreateDate(requestForCooperationService.findRequest(id).getCreateDate()); requestForCooperationService.updateRequest(request); return "redirect:request"; } diff --git a/src/main/java/com/example/demo/speaker/controller/RequestForCooperationController.java b/src/main/java/com/example/demo/speaker/controller/RequestForCooperationController.java index 552bbda..7645856 100644 --- a/src/main/java/com/example/demo/speaker/controller/RequestForCooperationController.java +++ b/src/main/java/com/example/demo/speaker/controller/RequestForCooperationController.java @@ -45,7 +45,7 @@ public class RequestForCooperationController { //@RequestBody RequestForCooperationDTO requestDTO) { var company = companyService.findCompany(nameCompany); var emp = employeeService.findWorker(sort); - var request = new RequestForCooperation(company, new Date(), type == 0 ? TypeOfRequestEnum.DEVELOP : TypeOfRequestEnum.TRACKING, comment); + var request = new RequestForCooperation(company, new Date(), type == 0 ? TypeOfRequestEnum.DEVELOP : TypeOfRequestEnum.TRACKING, comment, emp); return requestForCooperationService.addRequest(new RequestForCooperationDTO(request)); } diff --git a/src/main/java/com/example/demo/speaker/model/RequestForCooperation.java b/src/main/java/com/example/demo/speaker/model/RequestForCooperation.java index e57d82a..fed093f 100644 --- a/src/main/java/com/example/demo/speaker/model/RequestForCooperation.java +++ b/src/main/java/com/example/demo/speaker/model/RequestForCooperation.java @@ -27,19 +27,20 @@ public class RequestForCooperation { public RequestForCooperation() { } Random r = new Random(); - public RequestForCooperation(Company name, Date createDate, TypeOfRequestEnum type, String text) { + public RequestForCooperation(Company name, Date createDate, TypeOfRequestEnum type, String text, Employee employee) { this.nameCompany = name; this.createDate = createDate; this.comment = text; this.typeSotr = type; this.id = r.nextLong(); + this.sotr = employee; } - public RequestForCooperation(Long id, Company name, Date createDate, TypeOfRequestEnum type, String text) { + public RequestForCooperation(Long id, Company name, Date createDate, + TypeOfRequestEnum type, String text) { this.nameCompany = name; this.createDate = createDate; this.comment = text; this.typeSotr = type; - this.id = id; } public Company getName() diff --git a/src/main/java/com/example/demo/speaker/service/RequestForCooperationService.java b/src/main/java/com/example/demo/speaker/service/RequestForCooperationService.java index 0b5e217..7ea80b3 100644 --- a/src/main/java/com/example/demo/speaker/service/RequestForCooperationService.java +++ b/src/main/java/com/example/demo/speaker/service/RequestForCooperationService.java @@ -25,10 +25,13 @@ public class RequestForCooperationService { @Transactional public RequestForCooperation addRequest(RequestForCooperationDTO requestDTO) { - final RequestForCooperation request = new RequestForCooperation(requestDTO.getNameCompany(), + var company = companyService.findCompany(requestDTO.getNameCompany()); + var empl = employeeService.findWorker(requestDTO.getSotr()); + final RequestForCooperation request = new RequestForCooperation(company, requestDTO.getCreateDate(), requestDTO.getType(), - requestDTO.getComment()); + requestDTO.getComment(), + empl); requestForCooperationRepository.save(request); return request; } @@ -49,7 +52,7 @@ public class RequestForCooperationService { final RequestForCooperation currentReport = findRequest(requestDTO.getId()); currentReport.setApproveDate(requestDTO.getApproveDate()); currentReport.setActive(requestDTO.getActive()); - currentReport.setUser(employeeService.findWorker(requestDTO.getSotr().getId())); + currentReport.setUser(employeeService.findWorker(requestDTO.getSotr())); requestForCooperationRepository.save(currentReport); return currentReport; } diff --git a/src/main/resources/templates/appointment.html b/src/main/resources/templates/appointment.html index 99bada8..5c357c9 100644 --- a/src/main/resources/templates/appointment.html +++ b/src/main/resources/templates/appointment.html @@ -13,7 +13,7 @@