add front

This commit is contained in:
DozorovaA.A 2023-05-25 15:06:02 +04:00
parent 17f2a1e768
commit 4b69a4ff4b
10 changed files with 1112 additions and 31 deletions

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -18,16 +18,12 @@ public class AppointmentController {
this.appointmentService = appointmentService;
}
@PostMapping("/add")
public AppointmentDTO addAppointment(@RequestBody AppointmentDTO appointmentDTO){
try
{
return new AppointmentDTO(appointmentService.addAppointment(new AppointmentDTO(new Appointment(appointmentDTO.getName()))));
public AppointmentDTO addAppointment(String name){
Random r = new Random();
var app = new Appointment(r.nextLong(), name);
return new AppointmentDTO(appointmentService.addAppointment(new AppointmentDTO(app)));
}
catch(Exception e)
{
return null;
}
}
@PutMapping("/{id}")

View File

@ -9,7 +9,7 @@ public class AppointmentDTO {
public AppointmentDTO(Appointment appointment)
{
this.id = appointment.getId();
this.name = appointment.getName();
this.name = appointment.getName();;
}
public AppointmentDTO(){}

View File

@ -21,12 +21,15 @@ public class CompanyController {
public CompanyController(CompanyService _companyService) {
this.companyService = _companyService;
}
@PostMapping
public CompanyDTO addCompany(@RequestBody CompanyDTO companyDTO) {
return new CompanyDTO(companyService.addCompany(companyDTO));
@PostMapping("/add")
public CompanyDTO addCompany(@RequestParam("name") String name, @RequestParam("legalAdressCompany") String legalAdressCompany,
@RequestParam("adressCompany") String adressCompany,
@RequestParam("contactEmail") String contactEmail) {
var company = new Company(name, legalAdressCompany, adressCompany, contactEmail);
return new CompanyDTO(companyService.addCompany(new CompanyDTO(company)));
}
@PutMapping("/{id}")
@PutMapping("/update/{id}")
public CompanyDTO updateCompany(@PathVariable Long id,@RequestBody CompanyDTO companyDTO) {
return new CompanyDTO(companyService.updateCompany(id,companyDTO));
}

View File

@ -15,7 +15,7 @@ public class CompanyDTO {
private String legalAdressCompany;
private String adressCompany;
private String contactEmail;
private List<RequestForCooperationDTO> requests = new ArrayList<>();
// private List<RequestForCooperationDTO> requests = new ArrayList<>();
public CompanyDTO(Company company)
{
@ -24,10 +24,7 @@ public class CompanyDTO {
this.legalAdressCompany = company.getLegalAdressCompany();
this.adressCompany = company.getAdressCompany();
this.contactEmail = company.getContactEmail();
this.requests = company.getList() == null ? null : company.getList()
.stream()
.map(RequestForCooperationDTO::new)
.toList();
}
public long getId() {
@ -42,5 +39,4 @@ public class CompanyDTO {
public String getLegalAdressCompany() { return legalAdressCompany; }
public List<RequestForCooperationDTO> getRequests() { return requests; }
}

View File

@ -34,9 +34,10 @@ public class EmployeeController {
return employeeService.findAllWorkers();
}
@PostMapping("/")
public EmployeeDTO createWorker(@RequestBody EmployeeDTO emplyeeDTO) {
return new EmployeeDTO(employeeService.addWorker(emplyeeDTO));
@PostMapping("/add")
public EmployeeDTO createWorker(@RequestParam("name") String name, @RequestParam("appointmentId") Long appointmentId) {
var Employee = new Employee(name, appointmentService.findAppointment(appointmentId));
return new EmployeeDTO(employeeService.addWorker(new EmployeeDTO(Employee)));
}
@PutMapping("/{id}")

View File

@ -1,21 +1,26 @@
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.service.CompanyService;
import com.example.demo.speaker.service.EmployeeService;
import com.example.demo.speaker.service.RequestForCooperationService;
import org.springframework.web.bind.annotation.*;
import java.util.Date;
import java.util.List;
@RestController
@RequestMapping("/request")
@RequestMapping("/requests")
public class RequestForCooperationController {
private final RequestForCooperationService requestForCooperationService;
private final CompanyService companyService;
private final EmployeeService employeeService;
public RequestForCooperationController(RequestForCooperationService requestForCooperationService, CompanyService companyService) {
public RequestForCooperationController(RequestForCooperationService requestForCooperationService, CompanyService companyService, EmployeeService employeeService) {
this.requestForCooperationService = requestForCooperationService;
this.companyService = companyService;
this.employeeService = employeeService;
}
@GetMapping("/{id}")
@ -28,10 +33,19 @@ public class RequestForCooperationController {
return requestForCooperationService.findAllRequests();
}
@PostMapping("/")
public RequestForCooperation createRequest(@RequestBody RequestForCooperationDTO requestDTO) {
@PostMapping("/add")
public RequestForCooperation createRequest(@PathVariable Long nameCompany,
@PathVariable String comment,
@PathVariable Integer isActive,
@PathVariable Long sort,
@PathVariable Long type
){
return requestForCooperationService.addRequest(requestDTO);
//@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);
return requestForCooperationService.addRequest(new RequestForCooperationDTO(request));
}
@PutMapping("/{id}")

View File

@ -11,7 +11,7 @@ import static java.lang.Math.abs;
public class Appointment {
private String name;
@Id
@GeneratedValue
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;
public String getName()
{

View File

@ -8,6 +8,7 @@ import org.springframework.transaction.annotation.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.Random;
@Service
public class AppointmentService {
@ -21,8 +22,8 @@ private final IAppointmentRepository appointmentRepository;
public Appointment addAppointment(AppointmentDTO appointmentDTO) {
try
{
Appointment appointment = new Appointment(appointmentDTO.getId(), appointmentDTO.getName());
appointmentRepository.saveAndFlush(appointment);
Appointment appointment = new Appointment(appointmentDTO.getName());
appointmentRepository.save(appointment);
return appointment;
}
catch(Exception e)