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; + } }