This commit is contained in:
DozorovaA.A 2023-05-09 19:18:27 +04:00
parent 69fef2a6c7
commit 95f1c8f46c
7 changed files with 38 additions and 72 deletions

View File

@ -40,6 +40,7 @@ public class AppointmentController {
return new AppointmentDTO(appointmentService.findAppointment(id)); return new AppointmentDTO(appointmentService.findAppointment(id));
} }
@GetMapping("/list")
public List<AppointmentDTO> findAllAppointments() { public List<AppointmentDTO> findAllAppointments() {
return appointmentService.findAllAppointments() return appointmentService.findAllAppointments()
.stream() .stream()

View File

@ -22,12 +22,12 @@ public class CompanyController {
this.companyService = _companyService; this.companyService = _companyService;
} }
@PostMapping @PostMapping
public CompanyDTO addAppointment(@RequestBody CompanyDTO companyDTO) { public CompanyDTO addCompany(@RequestBody CompanyDTO companyDTO) {
return new CompanyDTO(companyService.addCompany(companyDTO)); return new CompanyDTO(companyService.addCompany(companyDTO));
} }
@PutMapping("/{id}") @PutMapping("/{id}")
public CompanyDTO updateAppointment(@PathVariable Long id,@RequestBody CompanyDTO companyDTO) { public CompanyDTO updateCompany(@PathVariable Long id,@RequestBody CompanyDTO companyDTO) {
return new CompanyDTO(companyService.updateCompany(id,companyDTO)); return new CompanyDTO(companyService.updateCompany(id,companyDTO));
} }
@ -45,7 +45,7 @@ public class CompanyController {
public CompanyDTO findCompany(@PathVariable Long id) { public CompanyDTO findCompany(@PathVariable Long id) {
return new CompanyDTO(companyService.findCompany(id)); return new CompanyDTO(companyService.findCompany(id));
} }
@GetMapping("/list")
public List<CompanyDTO> findAllCompanies() { public List<CompanyDTO> findAllCompanies() {
return companyService.findAllCompanies() return companyService.findAllCompanies()
.stream() .stream()

View File

@ -11,7 +11,7 @@ import org.springframework.web.bind.annotation.*;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping("/workers") @RequestMapping("/employee")
public class EmployeeController { public class EmployeeController {
private final EmployeeService employeeService; private final EmployeeService employeeService;
private final RequestForCooperationService requestForCooperationService; private final RequestForCooperationService requestForCooperationService;
@ -29,7 +29,7 @@ public class EmployeeController {
return employeeService.findWorker(id); return employeeService.findWorker(id);
} }
@GetMapping("/") @GetMapping("/all")
public List<Employee> getWorkers() { public List<Employee> getWorkers() {
return employeeService.findAllWorkers(); return employeeService.findAllWorkers();
} }
@ -39,7 +39,7 @@ public class EmployeeController {
return new EmployeeDTO(employeeService.addWorker(emplyeeDTO)); return new EmployeeDTO(employeeService.addWorker(emplyeeDTO));
} }
@PatchMapping("/{id}") @PutMapping("/{id}")
public EmployeeDTO updateWorker(@PathVariable Long id,@RequestBody EmployeeDTO employeeDTO) { public EmployeeDTO updateWorker(@PathVariable Long id,@RequestBody EmployeeDTO employeeDTO) {
return new EmployeeDTO(employeeService.updateReportWorker(id, employeeDTO)); return new EmployeeDTO(employeeService.updateReportWorker(id, employeeDTO));
} }

View File

@ -1,31 +1,20 @@
package com.example.demo.speaker.controller; package com.example.demo.speaker.controller;
import com.example.demo.speaker.model.RequestForCooperation; import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.model.TypeOfRequestEnum;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.service.AppointmentService;
import com.example.demo.speaker.service.CompanyService; import com.example.demo.speaker.service.CompanyService;
import com.example.demo.speaker.service.RequestForCooperationService; import com.example.demo.speaker.service.RequestForCooperationService;
import com.example.demo.speaker.service.EmployeeService;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List; import java.util.List;
@RestController @RestController
@RequestMapping("/reports") @RequestMapping("/request")
public class RequestForCooperationController { public class RequestForCooperationController {
private final RequestForCooperationService requestForCooperationService; private final RequestForCooperationService requestForCooperationService;
private final EmployeeService employeeService;
private final AppointmentService appointmentService;
private final CompanyService companyService; private final CompanyService companyService;
public RequestForCooperationController(RequestForCooperationService requestForCooperationService, CompanyService companyService) {
public RequestForCooperationController(RequestForCooperationService requestForCooperationService, EmployeeService employeeService,
AppointmentService appointmentService, CompanyService companyService) {
this.requestForCooperationService = requestForCooperationService; this.requestForCooperationService = requestForCooperationService;
this.employeeService = employeeService;
this.appointmentService = appointmentService;
this.companyService = companyService; this.companyService = companyService;
} }
@ -34,40 +23,20 @@ public class RequestForCooperationController {
return requestForCooperationService.findRequest(id); return requestForCooperationService.findRequest(id);
} }
@GetMapping("/") @GetMapping("/all")
public List<RequestForCooperation> getRequests() { public List<RequestForCooperation> getRequests() {
return requestForCooperationService.findAllRequests(); return requestForCooperationService.findAllRequests();
} }
@PostMapping("/") @PostMapping("/")
public RequestForCooperation createRequest(@RequestParam("companyId") Long companyId, public RequestForCooperation createRequest(@RequestBody RequestForCooperationDTO requestDTO) {
@RequestParam("createDate") Date createDate,
@RequestParam("Type") String type,
@RequestParam("Text") String Text) {
final TypeOfRequestEnum typeSotr;
switch (type)
{
case "TRACKING":
typeSotr = TypeOfRequestEnum.TRACKING;
break;
case "DEVELOP":
typeSotr = TypeOfRequestEnum.DEVELOP;
break;
default:
typeSotr = TypeOfRequestEnum.TRACKING;
break;
}
return requestForCooperationService.addRequest(companyService.findCompany(companyId), createDate, typeSotr, Text); return requestForCooperationService.addRequest(requestDTO);
} }
@PatchMapping("/{id}") @PutMapping("/{id}")
public RequestForCooperation updateRequest(@PathVariable Long id, public RequestForCooperationDTO updateRequest(@PathVariable Long id, @RequestBody RequestForCooperationDTO requestDTO) {
@RequestParam("approveDate") Date approveDate, return new RequestForCooperationDTO(requestForCooperationService.updateRequest(requestDTO));
@RequestParam("isActive") Boolean isActive,
@RequestParam("Worker") Long idWorker) {
final Employee employee = employeeService.findWorker(idWorker);
return requestForCooperationService.updateRequest(id, approveDate, isActive, employee);
} }
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@ -75,28 +44,8 @@ public class RequestForCooperationController {
return requestForCooperationService.deleteRequest(id); return requestForCooperationService.deleteRequest(id);
} }
@PostMapping("/list") @GetMapping("/Company={id}")
public String ListOfRequest(@RequestParam("Type") String type) { public List<RequestForCooperation> ListOfRequest(@PathVariable Long id) {
var List = requestForCooperationService.findAllRequests(); return requestForCooperationService.getRequestsOfCompany(companyService.findCompany(id));
final TypeOfRequestEnum typeSotr;
switch (type)
{
case "TRACKING":
typeSotr = TypeOfRequestEnum.TRACKING;
break;
case "DEVELOP":
typeSotr = TypeOfRequestEnum.DEVELOP;
break;
default:
typeSotr = TypeOfRequestEnum.TRACKING;
break;
}
EmployeeService employeeService = new EmployeeService(employeeRepository, appointmentRepository, requestForCooperationRepository);
String result = "";
for (var i : List) {
var Worker = employeeService.findWorker(i.getWorker().getId());
result += i.toString() + "Type: " + typeSotr.toString() + "Worker: "+Worker.toString() + "\n\r";
}
return result;
} }
} }

View File

@ -34,7 +34,7 @@ private final IAppointmentRepository appointmentRepository;
@Transactional(readOnly = true) @Transactional(readOnly = true)
public Employee findWorker(Long id) { public Employee findWorker(Long id) {
final Optional<Employee> employee = employeeRepository.findById(id); final Optional<Employee> employee = employeeRepository.findById(id);
return employee.orElseThrow(()->new EmployeeNotFoundException(id); return employee.orElseThrow(()->new EmployeeNotFoundException(id));
} }
@Transactional(readOnly = true) @Transactional(readOnly = true)

View File

@ -1,8 +1,10 @@
package com.example.demo.speaker.service; package com.example.demo.speaker.service;
import com.example.demo.speaker.controller.CompanyDTO;
import com.example.demo.speaker.controller.RequestForCooperationDTO; import com.example.demo.speaker.controller.RequestForCooperationDTO;
import com.example.demo.speaker.model.Company;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.model.RequestForCooperation; import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.repository.IEmployeeRepository;
import com.example.demo.speaker.repository.IRequestForCooperationRepository; import com.example.demo.speaker.repository.IRequestForCooperationRepository;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -14,10 +16,12 @@ import java.util.Optional;
public class RequestForCooperationService { public class RequestForCooperationService {
private final IRequestForCooperationRepository requestForCooperationRepository; private final IRequestForCooperationRepository requestForCooperationRepository;
private final EmployeeService employeeService; private final EmployeeService employeeService;
private final CompanyService companyService;
public RequestForCooperationService(IRequestForCooperationRepository requestForCooperationRepository, EmployeeService employeeRepository) { public RequestForCooperationService(IRequestForCooperationRepository requestForCooperationRepository, EmployeeService employeeRepository, CompanyService companyService) {
this.requestForCooperationRepository = requestForCooperationRepository; this.requestForCooperationRepository = requestForCooperationRepository;
this.employeeService = employeeRepository; this.employeeService = employeeRepository;
this.companyService = companyService;
} }
@Transactional @Transactional
@ -62,4 +66,16 @@ public class RequestForCooperationService {
public void deleteAllRequests() { public void deleteAllRequests() {
requestForCooperationRepository.deleteAll(); requestForCooperationRepository.deleteAll();
} }
@Transactional
public Employee getEmployeeOfRequest(Long id)
{
return requestForCooperationRepository.findWorkerByRequest(findRequest(id));
}
@Transactional
public List<RequestForCooperation> getRequestsOfCompany(Company companyDTO)
{
Company company = companyService.findCompany(companyDTO.getId());
return requestForCooperationRepository.findRequestByCompany(company);
}
} }

View File

@ -23,6 +23,6 @@ import java.util.stream.Stream;
@SpringBootTest @SpringBootTest
public class JPATests { public class JPATests {
} }