PMT-43: Implement Tests and Minor Tweaks
This commit is contained in:
parent
89d383cc5d
commit
289cf7e120
3 changed files with 88 additions and 13 deletions
57
api/pmt.yml
57
api/pmt.yml
|
@ -77,6 +77,45 @@ components:
|
||||||
qualificationId:
|
qualificationId:
|
||||||
type: integer
|
type: integer
|
||||||
format: int64
|
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:
|
responses:
|
||||||
Ok:
|
Ok:
|
||||||
description: "OK"
|
description: "OK"
|
||||||
|
@ -169,10 +208,10 @@ paths:
|
||||||
format: int64
|
format: int64
|
||||||
required: true
|
required: true
|
||||||
requestBody:
|
requestBody:
|
||||||
content:
|
content:
|
||||||
application/json:
|
application/json:
|
||||||
schema:
|
schema:
|
||||||
$ref: "#/components/schemas/AddEmployeeDTO"
|
$ref: "#/components/schemas/AddEmployeeDTO"
|
||||||
responses:
|
responses:
|
||||||
204:
|
204:
|
||||||
description: "Employee successfully added to the specific Project"
|
description: "Employee successfully added to the specific Project"
|
||||||
|
@ -181,7 +220,7 @@ paths:
|
||||||
404:
|
404:
|
||||||
$ref: "#/components/responses/NotFound"
|
$ref: "#/components/responses/NotFound"
|
||||||
409:
|
409:
|
||||||
$ref: "#/components/responses/Conflict"
|
$ref: "#/components/responses/Conflict"
|
||||||
422:
|
422:
|
||||||
$ref: "#/components/responses/UnprocessableContent"
|
$ref: "#/components/responses/UnprocessableContent"
|
||||||
500:
|
500:
|
||||||
|
@ -257,10 +296,12 @@ paths:
|
||||||
required: true
|
required: true
|
||||||
responses:
|
responses:
|
||||||
200:
|
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:
|
404:
|
||||||
$ref: '#/components/responses/NotFound'
|
$ref: '#/components/responses/NotFound'
|
||||||
500:
|
500:
|
||||||
$ref: "#/components/responses/InternalError"
|
$ref: "#/components/responses/InternalError"
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -155,14 +155,15 @@ public class ApiController implements DefaultApi {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<List<EmployeeResponseDTO>> getAListOfAllEmployeesFromASpecificProject(Long id) {
|
public ResponseEntity<GetEmployeesByProjectDTO> getAListOfAllEmployeesFromASpecificProject(Long id) {
|
||||||
if (!projectRepository.existsById(id)) {
|
if (!projectRepository.existsById(id)) {
|
||||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetEmployeesByProjectDTO dto = new GetEmployeesByProjectDTO();
|
||||||
List<Allocation> allocationsByProject = allocationRepository.findAllByProjectId(id);
|
List<Allocation> allocationsByProject = allocationRepository.findAllByProjectId(id);
|
||||||
if (allocationsByProject.isEmpty()) {
|
if (allocationsByProject.isEmpty()) {
|
||||||
return new ResponseEntity<>(Collections.emptyList(), HttpStatus.OK);
|
return new ResponseEntity<>(dto, HttpStatus.OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
Set<Long> employeeIds = allocationsByProject.stream()
|
Set<Long> employeeIds = allocationsByProject.stream()
|
||||||
|
@ -170,16 +171,17 @@ public class ApiController implements DefaultApi {
|
||||||
.collect(Collectors.toSet());
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<EmployeeResponseDTO> employees = apiClientFactory.getEmployeeApi().findAll1().stream()
|
List<EmployeeDTO> employees = apiClientFactory.getEmployeeApi().findAll1().stream()
|
||||||
.filter(employeeResponseDTO -> employeeIds.contains(employeeResponseDTO.getId()))
|
.filter(employeeResponseDTO -> employeeIds.contains(employeeResponseDTO.getId()))
|
||||||
|
.map(mapper::map)
|
||||||
.toList();
|
.toList();
|
||||||
return new ResponseEntity<>(employees, HttpStatus.OK);
|
dto.setEmployees(employees);
|
||||||
|
return new ResponseEntity<>(dto, HttpStatus.OK);
|
||||||
} catch (RestClientException exception) {
|
} catch (RestClientException exception) {
|
||||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Was wenn, die Liste der Allocation und die Liste der EmployeeResponseDTO nicht die gleiche Anzahl haben.
|
// 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.
|
// Das EmployeeResponseDTO wird vom EmployeeService gestellt, sollte man die Daten auf eigenes DTO mappen.
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,14 @@ package de.hmmh.pmt.util;
|
||||||
import de.hmmh.pmt.db.Project;
|
import de.hmmh.pmt.db.Project;
|
||||||
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
||||||
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
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 org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class Mapper {
|
public class Mapper {
|
||||||
public Project map(CreateProjectDTO dto) {
|
public Project map(CreateProjectDTO dto) {
|
||||||
|
@ -29,4 +35,30 @@ public class Mapper {
|
||||||
dto.setPlannedEnd(project.getPlannedEnd());
|
dto.setPlannedEnd(project.getPlannedEnd());
|
||||||
return dto;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue