PMT-40: alle Projekte eines Bestimmten Mitarbeiters abfragen #18
1 changed files with 10 additions and 7 deletions
|
@ -241,16 +241,19 @@ public class ApiController implements DefaultApi {
|
|||
|
||||
@Override
|
||||
public ResponseEntity<EmployeeProjectsDTO> getAListOfAllProjectsFromASpecificEmployee(Long id) {
|
||||
ApiTools.CheckEmployeeRecord employeeRecord = apiTools.checkEmployeeExists(id);
|
||||
if (employeeRecord.status() != HttpStatus.OK) {
|
||||
return new ResponseEntity<>(employeeRecord.status());
|
||||
}
|
||||
|
||||
List<Allocation> allocationsByEmployee = allocationRepository.findAllByEmployeeId(id);
|
||||
|
||||
Set<Project> projects = allocationsByEmployee.stream()
|
||||
.map(Allocation::getProject)
|
||||
.collect(Collectors.toSet());
|
||||
|
||||
EmployeeProjectsDTO response = new EmployeeProjectsDTO();
|
||||
for (Project project : projects) {
|
||||
response.addProjectsItem(mapper.mapProject(project));
|
||||
response.setProjects(new ArrayList<>());
|
||||
for (Allocation allocation : allocationsByEmployee) {
|
||||
response.addProjectsItem(mapper.mapProject(allocation.getProject()));
|
||||
}
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
|
||||
return ResponseEntity.ok(response);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue