From a9ae63bf8eb1c2d8a866534d6a35a570d5737ac9 Mon Sep 17 00:00:00 2001 From: Rajbir Singh Date: Wed, 23 Oct 2024 08:46:53 +0200 Subject: [PATCH] PMT-26 refactor naming pmt.yml, ApiController, Mapper --- api/pmt.yml | 12 ++++++------ src/main/java/de/hmmh/pmt/ApiController.java | 9 +++------ src/main/java/de/hmmh/pmt/util/Mapper.java | 14 +++++++------- 3 files changed, 16 insertions(+), 19 deletions(-) diff --git a/api/pmt.yml b/api/pmt.yml index 15b00bc..9f03780 100644 --- a/api/pmt.yml +++ b/api/pmt.yml @@ -77,7 +77,7 @@ components: qualificationId: type: integer format: int64 - EmployeeDTO: + Employee: type: object properties: id: @@ -100,8 +100,8 @@ components: skillSet: type: array items: - $ref: '#/components/schemas/QualificationDTO' - QualificationDTO: + $ref: '#/components/schemas/Qualification' + Qualification: type: object properties: skill: @@ -109,13 +109,13 @@ components: id: type: integer format: int64 - GetEmployeesByProjectDTO: + ProjectEmployeesDTO: type: object properties: employees: type: array items: - $ref: "#/components/schemas/EmployeeDTO" + $ref: "#/components/schemas/Employee" responses: Ok: description: "OK" @@ -299,7 +299,7 @@ paths: content: application/json: schema: - $ref: "#/components/schemas/GetEmployeesByProjectDTO" + $ref: "#/components/schemas/ProjectEmployeesDTO" description: 'Get a List of all Employees from a specific Project ' 404: $ref: '#/components/responses/NotFound' diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index e8f31e5..6c57d91 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -155,12 +155,12 @@ public class ApiController implements DefaultApi { } @Override - public ResponseEntity getAListOfAllEmployeesFromASpecificProject(Long id) { + public ResponseEntity getAListOfAllEmployeesFromASpecificProject(Long id) { if (!projectRepository.existsById(id)) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } - GetEmployeesByProjectDTO dto = new GetEmployeesByProjectDTO(); + ProjectEmployeesDTO dto = new ProjectEmployeesDTO(); List allocationsByProject = allocationRepository.findAllByProjectId(id); if (allocationsByProject.isEmpty()) { return new ResponseEntity<>(dto, HttpStatus.OK); @@ -171,7 +171,7 @@ public class ApiController implements DefaultApi { .collect(Collectors.toSet()); try { - List employees = apiClientFactory.getEmployeeApi().findAll1().stream() + List employees = apiClientFactory.getEmployeeApi().findAll1().stream() .filter(employeeResponseDTO -> employeeIds.contains(employeeResponseDTO.getId())) .map(mapper::map) .toList(); @@ -180,8 +180,5 @@ public class ApiController implements DefaultApi { } catch (RestClientException exception) { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } - - // Was wenn, die Liste der Allocation und die Liste der EmployeeResponseDTO nicht die gleiche Anzahl haben. - // Das EmployeeResponseDTO wird vom EmployeeService gestellt, sollte man die Daten auf eigenes DTO mappen. } } diff --git a/src/main/java/de/hmmh/pmt/util/Mapper.java b/src/main/java/de/hmmh/pmt/util/Mapper.java index c103feb..09ba201 100644 --- a/src/main/java/de/hmmh/pmt/util/Mapper.java +++ b/src/main/java/de/hmmh/pmt/util/Mapper.java @@ -3,8 +3,8 @@ package de.hmmh.pmt.util; import de.hmmh.pmt.db.Project; import de.hmmh.pmt.dtos.CreateProjectDTO; import de.hmmh.pmt.dtos.CreatedProjectDTO; -import de.hmmh.pmt.dtos.EmployeeDTO; -import de.hmmh.pmt.dtos.QualificationDTO; +import de.hmmh.pmt.dtos.Employee; +import de.hmmh.pmt.dtos.Qualification ; import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO; import de.hmmh.pmt.employee.dtos.QualificationGetDTO; import org.springframework.stereotype.Component; @@ -36,8 +36,8 @@ public class Mapper { return dto; } - public EmployeeDTO map(EmployeeResponseDTO employeeResponseDTO) { - EmployeeDTO dto = new EmployeeDTO(); + public Employee map(EmployeeResponseDTO employeeResponseDTO) { + Employee dto = new Employee(); dto.setId(employeeResponseDTO.getId()); dto.setLastName(employeeResponseDTO.getLastName()); dto.setFirstName(employeeResponseDTO.getFirstName()); @@ -46,7 +46,7 @@ public class Mapper { dto.setCity(employeeResponseDTO.getCity()); dto.setPhone(employeeResponseDTO.getPhone()); - List skillSet = employeeResponseDTO.getSkillSet().stream() + List skillSet = employeeResponseDTO.getSkillSet().stream() .map(this::map) .toList(); @@ -54,8 +54,8 @@ public class Mapper { return dto; } - private QualificationDTO map(QualificationGetDTO qualificationGetDTO) { - QualificationDTO dto = new QualificationDTO(); + private Qualification map(QualificationGetDTO qualificationGetDTO) { + Qualification dto = new Qualification (); dto.setId(qualificationGetDTO.getId()); dto.setSkill(qualificationGetDTO.getSkill()); return dto;