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));
}
@GetMapping("/list")
public List<AppointmentDTO> findAllAppointments() {
return appointmentService.findAllAppointments()
.stream()

View File

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

View File

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

View File

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

View File

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

View File

@ -1,8 +1,10 @@
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.model.Company;
import com.example.demo.speaker.model.Employee;
import com.example.demo.speaker.model.RequestForCooperation;
import com.example.demo.speaker.repository.IEmployeeRepository;
import com.example.demo.speaker.repository.IRequestForCooperationRepository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@ -14,10 +16,12 @@ import java.util.Optional;
public class RequestForCooperationService {
private final IRequestForCooperationRepository requestForCooperationRepository;
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.employeeService = employeeRepository;
this.companyService = companyService;
}
@Transactional
@ -62,4 +66,16 @@ public class RequestForCooperationService {
public void deleteAllRequests() {
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);
}
}