PMT-26 changed pmt.yml, Mapper, ApiController
All checks were successful
Quality Check / Validate OAS (push) Successful in 33s
Quality Check / Linting (push) Successful in 1m10s
Quality Check / Static Analysis (push) Successful in 1m17s
Quality Check / Testing (push) Successful in 1m16s
Quality Check / Validate OAS (pull_request) Successful in 33s
Quality Check / Linting (pull_request) Successful in 1m9s
Quality Check / Static Analysis (pull_request) Successful in 1m18s
Quality Check / Testing (pull_request) Successful in 1m16s

This commit is contained in:
Rajbir Singh 2024-10-22 18:15:14 +02:00
parent 94298293a8
commit b3327ad351
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:
@ -226,10 +265,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

@ -145,14 +145,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()
@ -160,16 +161,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;
}
}