Compare commits

...

2 commits

Author SHA1 Message Date
Rajbir Singh
9692f1f179 PMT-26 get all Employees from a specific Project
Some checks failed
Quality Check / Validate OAS (push) Successful in 33s
Quality Check / Linting (push) Failing after 50s
Quality Check / Static Analysis (push) Failing after 51s
Quality Check / Testing (push) Failing after 50s
2024-10-22 15:10:13 +02:00
Rajbir Singh
f941cad4b9 PMT-26 Define Endpoint 2024-10-21 22:24:48 +02:00
3 changed files with 52 additions and 2 deletions

View file

@ -78,6 +78,8 @@ components:
type: integer
format: int64
responses:
Ok:
description: "OK"
Unauthorized:
description: "Unauthorized"
NotFound:
@ -210,3 +212,24 @@ paths:
type: string
500:
$ref: "#/components/responses/InternalError"
/project/{id}/employees:
get:
description: "getAllEmployees"
operationId: "Get a List of all Employees from a specific Project"
parameters:
- in: path
name: id
schema:
type: integer
format: int64
required: true
responses:
200:
$ref: '#/components/responses/Ok'
404:
$ref: '#/components/responses/NotFound'
500:
$ref: "#/components/responses/InternalError"

View file

@ -20,8 +20,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}")
@ -143,4 +143,30 @@ public class ApiController implements DefaultApi {
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);
}
}

View file

@ -7,4 +7,5 @@ import java.util.List;
public interface AllocationRepository extends JpaRepository<Allocation, AllocationId> {
List<Allocation> findAllByEmployeeId(Long employeeId);
List<Allocation> findAllByProjectId(Long projectId);
}