PMT-43: Implement Tests and Minor Tweaks

This commit is contained in:
Dominik Säume 2024-10-23 13:10:57 +02:00
parent 89d383cc5d
commit 289cf7e120
3 changed files with 88 additions and 13 deletions

View file

@ -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"

View file

@ -155,14 +155,15 @@ public class ApiController implements DefaultApi {
}
@Override
public ResponseEntity<List<EmployeeResponseDTO>> getAListOfAllEmployeesFromASpecificProject(Long id) {
public ResponseEntity<GetEmployeesByProjectDTO> getAListOfAllEmployeesFromASpecificProject(Long id) {
if (!projectRepository.existsById(id)) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
GetEmployeesByProjectDTO dto = new GetEmployeesByProjectDTO();
List<Allocation> allocationsByProject = allocationRepository.findAllByProjectId(id);
if (allocationsByProject.isEmpty()) {
return new ResponseEntity<>(Collections.emptyList(), HttpStatus.OK);
return new ResponseEntity<>(dto, HttpStatus.OK);
}
Set<Long> employeeIds = allocationsByProject.stream()
@ -170,16 +171,17 @@ public class ApiController implements DefaultApi {
.collect(Collectors.toSet());
try {
List<EmployeeResponseDTO> employees = apiClientFactory.getEmployeeApi().findAll1().stream()
List<EmployeeDTO> 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.
}
}

View file

@ -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<QualificationDTO> 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;
}
}