diff --git a/data.mv.db b/data.mv.db index 0eb1899..9bea107 100644 Binary files a/data.mv.db and b/data.mv.db differ diff --git a/src/main/java/com/example/demo/speaker/controller/EmployeeController.java b/src/main/java/com/example/demo/speaker/controller/EmployeeController.java index ddb30f8..45b6d33 100644 --- a/src/main/java/com/example/demo/speaker/controller/EmployeeController.java +++ b/src/main/java/com/example/demo/speaker/controller/EmployeeController.java @@ -15,7 +15,7 @@ import java.util.List; public class EmployeeController { private final EmployeeService employeeService; private final RequestForCooperationService requestForCooperationService; - private final AppointmentService appointmentService; + private final AppointmentService appointmentService; public EmployeeController(EmployeeService employeeService, RequestForCooperationService requestForCooperationService, AppointmentService appointmentService) { @@ -40,9 +40,11 @@ public class EmployeeController { return new EmployeeDTO(employeeService.addWorker(new EmployeeDTO(Employee))); } - @PutMapping("/{id}") - public EmployeeDTO updateWorker(@PathVariable Long id,@RequestBody EmployeeDTO employeeDTO) { - return new EmployeeDTO(employeeService.updateReportWorker(id, employeeDTO)); + @PutMapping("/update") + public EmployeeDTO updateWorker(@RequestParam("id") Long id, @RequestParam("name") String name) { + var emp = employeeService.findWorker(id); + emp.setFio(name); + return new EmployeeDTO(employeeService.updateReportWorker(id, new EmployeeDTO(emp))); } @DeleteMapping("/{id}") @@ -51,15 +53,17 @@ public class EmployeeController { } @GetMapping("/id={id}") - public List getListOfReports(@PathVariable Long id) { - var employee = employeeService.findWorker(id); - return employeeService.findAllRequestsOfEmployee(employee); + public List getListOfReports(@PathVariable Long id) { + var employee = employeeService.findWorker(id); + return employeeService.findAllRequestsOfEmployee(employee); } - @GetMapping("/postId={postId}") - public List getListOfWorkers(@RequestParam("postId") Long id) { - final Appointment appointment = appointmentService.findAppointment(id); - return employeeService.findWorkerByPost(appointment); + @GetMapping("/postid={id}") + public List getListOfWorkers(@PathVariable Long id) { + final Appointment appointment = appointmentService.findAppointment(id); + var res = employeeService.findWorkerByPost(appointment); + return res; + //return new ArrayList(); } } 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 2ff3e50..a65b4b5 100644 --- a/src/main/java/com/example/demo/speaker/controller/RequestForCooperationController.java +++ b/src/main/java/com/example/demo/speaker/controller/RequestForCooperationController.java @@ -7,6 +7,9 @@ import com.example.demo.speaker.service.EmployeeService; import com.example.demo.speaker.service.RequestForCooperationService; import org.springframework.web.bind.annotation.*; +import java.text.DateFormat; +import java.text.ParseException; +import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; @@ -34,17 +37,15 @@ public class RequestForCooperationController { } @PostMapping("/add") - public RequestForCooperation createRequest(@PathVariable Long nameCompany, - @PathVariable String comment, - @PathVariable Integer isActive, - @PathVariable Long sort, - @PathVariable Long type - ){ + public RequestForCooperation createRequest(@RequestParam Long nameCompany, + @RequestParam String comment + ) throws ParseException { //@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 emp = employeeService.findWorker(1L); + DateFormat form = new SimpleDateFormat("yyyy-MM-dd"); + var request = new RequestForCooperation(656656L, company, form.parse("2023-06-13"), TypeOfRequestEnum.DEVELOP, 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..f3db9df 100644 --- a/src/main/java/com/example/demo/speaker/model/RequestForCooperation.java +++ b/src/main/java/com/example/demo/speaker/model/RequestForCooperation.java @@ -34,12 +34,13 @@ public class RequestForCooperation { this.typeSotr = type; this.id = r.nextLong(); } - public RequestForCooperation(Long id, Company name, Date createDate, TypeOfRequestEnum type, String text) { + public RequestForCooperation(Long id, Company name, Date createDate, TypeOfRequestEnum type, String text, Employee emp) { this.nameCompany = name; this.createDate = createDate; this.comment = text; this.typeSotr = type; this.id = id; + this.sotr = emp; } public Company getName() diff --git a/src/main/java/com/example/demo/speaker/repository/IEmployeeRepository.java b/src/main/java/com/example/demo/speaker/repository/IEmployeeRepository.java index b6692bf..b98fc6c 100644 --- a/src/main/java/com/example/demo/speaker/repository/IEmployeeRepository.java +++ b/src/main/java/com/example/demo/speaker/repository/IEmployeeRepository.java @@ -10,7 +10,7 @@ import org.springframework.data.repository.query.Param; import java.util.List; public interface IEmployeeRepository extends JpaRepository { - @Query("SELECT DISTINCT p.fio FROM Employee p where :appointment = p.appointment") + @Query("SELECT DISTINCT p FROM Employee p where :appointment = p.appointment") List getEmployeeByAppointment(@Param("appointment") Appointment appointment); @Query("SELECT DISTINCT p FROM RequestForCooperation p where :employee = p.sotr") diff --git a/src/main/java/com/example/demo/speaker/service/AppointmentService.java b/src/main/java/com/example/demo/speaker/service/AppointmentService.java index 67b37f6..7bbfbb8 100644 --- a/src/main/java/com/example/demo/speaker/service/AppointmentService.java +++ b/src/main/java/com/example/demo/speaker/service/AppointmentService.java @@ -35,7 +35,7 @@ private final IAppointmentRepository appointmentRepository; @Transactional(readOnly = true) public Appointment findAppointment(Long id) { final Optional appointment = appointmentRepository.findById(id); - return appointment.orElseThrow(()->new AppointmentNotFoundException(id)); + return appointment.get(); } @Transactional(readOnly = true)