PMT-26: Implement Endpoint

This commit is contained in:
Rajbir Singh 2024-10-23 13:17:04 +02:00 committed by Dominik Säume
parent 933ac666a8
commit b9d3170802
2 changed files with 62 additions and 2 deletions

View file

@ -19,8 +19,8 @@ import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.client.RestClientException;
import java.time.ZoneOffset;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;
@Controller
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
@ -153,4 +153,32 @@ public class ApiController implements DefaultApi {
allocationRepository.delete(allocation.get());
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
@Override
public ResponseEntity<ProjectEmployeesDTO> getAListOfAllEmployeesFromASpecificProject(Long id) {
if (!projectRepository.existsById(id)) {
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
ProjectEmployeesDTO dto = new ProjectEmployeesDTO();
List<Allocation> allocationsByProject = allocationRepository.findAllByProjectId(id);
if (allocationsByProject.isEmpty()) {
return new ResponseEntity<>(dto, HttpStatus.OK);
}
Set<Long> employeeIds = allocationsByProject.stream()
.map(Allocation::getEmployeeId)
.collect(Collectors.toSet());
try {
List<Employee> employees = apiClientFactory.getEmployeeApi().findAll1().stream()
.filter(employeeResponseDTO -> employeeIds.contains(employeeResponseDTO.getId()))
.map(mapper::map)
.toList();
dto.setEmployees(employees);
return new ResponseEntity<>(dto, HttpStatus.OK);
} catch (RestClientException exception) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View file

@ -3,8 +3,14 @@ package de.hmmh.pmt.util;
import de.hmmh.pmt.db.Project;
import de.hmmh.pmt.dtos.CreateProjectDTO;
import de.hmmh.pmt.dtos.CreatedProjectDTO;
import de.hmmh.pmt.dtos.Employee;
import de.hmmh.pmt.dtos.Qualification ;
import de.hmmh.pmt.employee.dtos.EmployeeResponseDTO;
import de.hmmh.pmt.employee.dtos.QualificationGetDTO;
import org.springframework.stereotype.Component;
import java.util.List;
@Component
public class Mapper {
public Project map(CreateProjectDTO dto) {
@ -29,4 +35,30 @@ public class Mapper {
dto.setPlannedEnd(project.getPlannedEnd());
return dto;
}
public Employee map(EmployeeResponseDTO employeeResponseDTO) {
Employee dto = new Employee();
dto.setId(employeeResponseDTO.getId());
dto.setLastName(employeeResponseDTO.getLastName());
dto.setFirstName(employeeResponseDTO.getFirstName());
dto.setStreet(employeeResponseDTO.getStreet());
dto.setPostcode(employeeResponseDTO.getPostcode());
dto.setCity(employeeResponseDTO.getCity());
dto.setPhone(employeeResponseDTO.getPhone());
List<Qualification > skillSet = employeeResponseDTO.getSkillSet().stream()
.map(this::map)
.toList();
dto.setSkillSet(skillSet);
return dto;
}
private Qualification map(QualificationGetDTO qualificationGetDTO) {
Qualification dto = new Qualification ();
dto.setId(qualificationGetDTO.getId());
dto.setSkill(qualificationGetDTO.getSkill());
return dto;
}
}