diff --git a/api/pmt.yml b/api/pmt.yml index 8ced600..15b00bc 100644 --- a/api/pmt.yml +++ b/api/pmt.yml @@ -77,6 +77,45 @@ components: qualificationId: type: integer format: int64 + EmployeeDTO: + type: object + properties: + id: + type: integer + format: int64 + lastName: + type: string + firstName: + type: string + street: + type: string + postcode: + maxLength: 5 + minLength: 5 + type: string + city: + type: string + phone: + type: string + skillSet: + type: array + items: + $ref: '#/components/schemas/QualificationDTO' + QualificationDTO: + type: object + properties: + skill: + type: string + id: + type: integer + format: int64 + GetEmployeesByProjectDTO: + type: object + properties: + employees: + type: array + items: + $ref: "#/components/schemas/EmployeeDTO" responses: Ok: description: "OK" @@ -169,10 +208,10 @@ paths: format: int64 required: true requestBody: - content: - application/json: - schema: - $ref: "#/components/schemas/AddEmployeeDTO" + content: + application/json: + schema: + $ref: "#/components/schemas/AddEmployeeDTO" responses: 204: description: "Employee successfully added to the specific Project" @@ -181,7 +220,7 @@ paths: 404: $ref: "#/components/responses/NotFound" 409: - $ref: "#/components/responses/Conflict" + $ref: "#/components/responses/Conflict" 422: $ref: "#/components/responses/UnprocessableContent" 500: @@ -257,10 +296,12 @@ paths: required: true responses: 200: - $ref: '#/components/responses/Ok' + content: + application/json: + schema: + $ref: "#/components/schemas/GetEmployeesByProjectDTO" + description: 'Get a List of all Employees from a specific Project ' 404: $ref: '#/components/responses/NotFound' 500: $ref: "#/components/responses/InternalError" - - diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index e1866ab..e8f31e5 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -155,14 +155,15 @@ 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(); List allocationsByProject = allocationRepository.findAllByProjectId(id); if (allocationsByProject.isEmpty()) { - return new ResponseEntity<>(Collections.emptyList(), HttpStatus.OK); + return new ResponseEntity<>(dto, HttpStatus.OK); } Set employeeIds = allocationsByProject.stream() @@ -170,16 +171,17 @@ 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(); - return new ResponseEntity<>(employees, HttpStatus.OK); + dto.setEmployees(employees); + return new ResponseEntity<>(dto, HttpStatus.OK); } 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 d5d7591..c103feb 100644 --- a/src/main/java/de/hmmh/pmt/util/Mapper.java +++ b/src/main/java/de/hmmh/pmt/util/Mapper.java @@ -3,8 +3,14 @@ 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.employee.dtos.EmployeeResponseDTO; +import de.hmmh.pmt.employee.dtos.QualificationGetDTO; import org.springframework.stereotype.Component; +import java.util.List; + @Component public class Mapper { public Project map(CreateProjectDTO dto) { @@ -29,4 +35,30 @@ public class Mapper { dto.setPlannedEnd(project.getPlannedEnd()); return dto; } + + public EmployeeDTO map(EmployeeResponseDTO employeeResponseDTO) { + EmployeeDTO dto = new EmployeeDTO(); + dto.setId(employeeResponseDTO.getId()); + dto.setLastName(employeeResponseDTO.getLastName()); + dto.setFirstName(employeeResponseDTO.getFirstName()); + dto.setStreet(employeeResponseDTO.getStreet()); + dto.setPostcode(employeeResponseDTO.getPostcode()); + dto.setCity(employeeResponseDTO.getCity()); + dto.setPhone(employeeResponseDTO.getPhone()); + + List skillSet = employeeResponseDTO.getSkillSet().stream() + .map(this::map) + .toList(); + + dto.setSkillSet(skillSet); + return dto; + } + + private QualificationDTO map(QualificationGetDTO qualificationGetDTO) { + QualificationDTO dto = new QualificationDTO(); + dto.setId(qualificationGetDTO.getId()); + dto.setSkill(qualificationGetDTO.getSkill()); + return dto; + } + }