diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index a740e23..ebb8879 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -241,16 +241,19 @@ public class ApiController implements DefaultApi { @Override public ResponseEntity getAListOfAllProjectsFromASpecificEmployee(Long id) { + ApiTools.CheckEmployeeRecord employeeRecord = apiTools.checkEmployeeExists(id); + if (employeeRecord.status() != HttpStatus.OK) { + return new ResponseEntity<>(employeeRecord.status()); + } + List allocationsByEmployee = allocationRepository.findAllByEmployeeId(id); - Set 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); } }