PMT-40: alle Projekte eines Bestimmten Mitarbeiters abfragen #18

Merged
SZUT-Dominik merged 4 commits from story/PMT-40-alle-projekte-eines-bestimmten into trunk 2024-10-24 09:02:40 +00:00
Showing only changes of commit 6b430ae251 - Show all commits

View file

@ -241,16 +241,19 @@ public class ApiController implements DefaultApi {
@Override @Override
public ResponseEntity<EmployeeProjectsDTO> getAListOfAllProjectsFromASpecificEmployee(Long id) { public ResponseEntity<EmployeeProjectsDTO> getAListOfAllProjectsFromASpecificEmployee(Long id) {
ApiTools.CheckEmployeeRecord employeeRecord = apiTools.checkEmployeeExists(id);
if (employeeRecord.status() != HttpStatus.OK) {
return new ResponseEntity<>(employeeRecord.status());
}
List<Allocation> allocationsByEmployee = allocationRepository.findAllByEmployeeId(id); List<Allocation> allocationsByEmployee = allocationRepository.findAllByEmployeeId(id);
Set<Project> projects = allocationsByEmployee.stream()
.map(Allocation::getProject)
.collect(Collectors.toSet());
EmployeeProjectsDTO response = new EmployeeProjectsDTO(); EmployeeProjectsDTO response = new EmployeeProjectsDTO();
for (Project project : projects) { response.setProjects(new ArrayList<>());
response.addProjectsItem(mapper.mapProject(project)); for (Allocation allocation : allocationsByEmployee) {
response.addProjectsItem(mapper.mapProject(allocation.getProject()));
} }
return new ResponseEntity<>(HttpStatus.OK);
return ResponseEntity.ok(response);
} }
} }