PMT-27-code fix and cleanup Controller

This commit is contained in:
Ole Kück 2024-10-23 11:11:58 +02:00
parent 8dff301457
commit 2ca9cfbadb
Signed by: SZUT-Ole
GPG key ID: 0A1DF1B37C4A1E4C

View file

@ -145,25 +145,12 @@ public class ApiController implements DefaultApi {
@Override
public ResponseEntity<Void> removeEmployeeFromProject(Long id, Long employeeId){
if (!projectRepository.existsById(id)) {
return ResponseEntity.notFound().build();
Optional<Allocation> allocation = allocationRepository.findById(new AllocationId(id, employeeId));
if (allocation.isEmpty()){
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
}
EmployeeResponseDTO employee;
try {
employee = apiClientFactory.getEmployeeApi().findById(employeeId);
} catch (HttpClientErrorException exception) {
return new ResponseEntity<>(exception.getStatusCode().equals(HttpStatus.NOT_FOUND)
? HttpStatus.NOT_FOUND
: HttpStatus.SERVICE_UNAVAILABLE);
} catch (RestClientException exception) {
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
}
Allocation allocation = allocationRepository.findById(id);
if (allocation.getEmployeeId().equals(employeeId)) {
allocationRepository.delete(allocation);
}
allocationRepository.delete(allocation.get());
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
}