From 096c25e33be204176290d0fd95653c7f17da3ac0 Mon Sep 17 00:00:00 2001 From: Rajbir Singh Date: Thu, 24 Oct 2024 09:49:53 +0200 Subject: [PATCH] PMT-40: Implement Endpoint MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Dominik Säume --- src/main/java/de/hmmh/pmt/ApiController.java | 16 ++++++++++++++++ src/main/java/de/hmmh/pmt/util/Mapper.java | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index 4d35d4f..a740e23 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; @@ -237,4 +238,19 @@ public class ApiController implements DefaultApi { return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR); } } + + @Override + public ResponseEntity getAListOfAllProjectsFromASpecificEmployee(Long id) { + 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)); + } + return new ResponseEntity<>(HttpStatus.OK); + } } diff --git a/src/main/java/de/hmmh/pmt/util/Mapper.java b/src/main/java/de/hmmh/pmt/util/Mapper.java index 63c22c4..0537580 100644 --- a/src/main/java/de/hmmh/pmt/util/Mapper.java +++ b/src/main/java/de/hmmh/pmt/util/Mapper.java @@ -82,4 +82,16 @@ public class Mapper { project.setPlannedEnd(dto.getPlannedEnd()); return project; } + public de.hmmh.pmt.dtos.Project mapProject(Project project){ + de.hmmh.pmt.dtos.Project dto = new de.hmmh.pmt.dtos.Project(); + dto.setId(project.getId()); + dto.setName(project.getName()); + dto.setGoal(project.getGoal()); + dto.setCustomerId(project.getCustomerId()); + dto.setAdministratorId(project.getAdministratorId()); + dto.setStart(project.getStart()); + dto.setPlannedEnd(project.getPlannedEnd()); + dto.setRealEnd(project.getRealEnd()); + return dto; + } }