PMT-26 get all Employees from a specific Project
This commit is contained in:
parent
1db0eb9630
commit
7cb75e449a
1 changed files with 28 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,30 @@ 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<List<EmployeeResponseDTO>> getAListOfAllEmployeesFromASpecificProject(Long id) {
|
||||||
|
if (!projectRepository.existsById(id)) {
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Allocation> allocationsByProject = allocationRepository.findAllByProjectId(id);
|
||||||
|
if (allocationsByProject.isEmpty()) {
|
||||||
|
return new ResponseEntity<>(Collections.emptyList(), HttpStatus.OK);
|
||||||
|
}
|
||||||
|
|
||||||
|
Set<Long> employeeIds = allocationsByProject.stream()
|
||||||
|
.map(Allocation::getEmployeeId)
|
||||||
|
.collect(Collectors.toSet());
|
||||||
|
|
||||||
|
List<EmployeeResponseDTO> employees = apiClientFactory.getEmployeeApi().findAll1().stream()
|
||||||
|
.filter(employeeResponseDTO -> employeeIds.contains(employeeResponseDTO.getId()))
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
// Was wenn, die Liste der Allocation und die Liste der EmployeeResponseDTO nicht die gleiche Anzahl haben.
|
||||||
|
// Das EmployeeResponseDTO wird vom EmployeeService gestellt, sollte man die Daten auf eigenes DTO mappen.
|
||||||
|
|
||||||
|
return new ResponseEntity<>(employees, HttpStatus.OK);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue