From 6b430ae2514b82ceb559cb08762474a4b40b1a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20S=C3=A4ume?= Date: Thu, 24 Oct 2024 10:30:56 +0200 Subject: [PATCH] PMT-40: Fix Endpoint --- src/main/java/de/hmmh/pmt/ApiController.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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); } }