From f0b7317d4930cc22c3bbcf9d86f55f1ba1693c0a Mon Sep 17 00:00:00 2001 From: Rajbir Singh Date: Wed, 23 Oct 2024 14:45:59 +0200 Subject: [PATCH] PMT-40 implements ApiController --- src/main/java/de/hmmh/pmt/ApiController.java | 25 ++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index c29c60b..d6b1521 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -3,6 +3,7 @@ package de.hmmh.pmt; import com.fasterxml.jackson.databind.ObjectMapper; import de.hmmh.pmt.db.*; +import de.hmmh.pmt.db.Project; import de.hmmh.pmt.dtos.*; import de.hmmh.pmt.employee.ApiClientFactory; import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO; @@ -225,4 +226,28 @@ public class ApiController implements DefaultApi { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } + + @Override + public ResponseEntity getAListOfAllProjectsFromASpecificEmployee(Long id) { + if (!projectRepository.existsById(id)) { + return new ResponseEntity<>(HttpStatus.NOT_FOUND); + } + + EmployeeProjectsDTO dto = new EmployeeProjectsDTO(); + List allocationsByEmployee = allocationRepository.findAllByEmployeeId(id); + if (allocationsByEmployee.isEmpty()) { + return new ResponseEntity<>(dto, HttpStatus.OK); + } + + Set projects = allocationsByEmployee.stream() + .map(Allocation::getProject) + .collect(Collectors.toSet()); + + EmployeeProjectsDTO response = new EmployeeProjectsDTO(); + + for (Project project : projects) { + response.addProjectsItem(mapper.mapProject(project)); + } + return new ResponseEntity<>(HttpStatus.OK); + } }