PMT-26: alle mitarbeiter eines #15
2 changed files with 62 additions and 2 deletions
|
@ -19,8 +19,8 @@ import org.springframework.web.client.HttpClientErrorException;
|
||||||
import org.springframework.web.client.RestClientException;
|
import org.springframework.web.client.RestClientException;
|
||||||
|
|
||||||
import java.time.ZoneOffset;
|
import java.time.ZoneOffset;
|
||||||
import java.util.List;
|
import java.util.*;
|
||||||
import java.util.Optional;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Controller
|
@Controller
|
||||||
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
|
@RequestMapping("${openapi.projectManagement.base-path:/api/v1}")
|
||||||
|
@ -153,4 +153,32 @@ public class ApiController implements DefaultApi {
|
||||||
allocationRepository.delete(allocation.get());
|
allocationRepository.delete(allocation.get());
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,14 @@ package de.hmmh.pmt.util;
|
||||||
import de.hmmh.pmt.db.Project;
|
import de.hmmh.pmt.db.Project;
|
||||||
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
import de.hmmh.pmt.dtos.CreateProjectDTO;
|
||||||
import de.hmmh.pmt.dtos.CreatedProjectDTO;
|
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 org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class Mapper {
|
public class Mapper {
|
||||||
public Project map(CreateProjectDTO dto) {
|
public Project map(CreateProjectDTO dto) {
|
||||||
|
@ -29,4 +35,30 @@ public class Mapper {
|
||||||
dto.setPlannedEnd(project.getPlannedEnd());
|
dto.setPlannedEnd(project.getPlannedEnd());
|
||||||
return dto;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue