story/PMT-27-mitarbeiter-aus-einem-projekt #17
1 changed files with 4 additions and 17 deletions
|
@ -145,25 +145,12 @@ public class ApiController implements DefaultApi {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ResponseEntity<Void> removeEmployeeFromProject(Long id, Long employeeId){
|
public ResponseEntity<Void> removeEmployeeFromProject(Long id, Long employeeId){
|
||||||
if (!projectRepository.existsById(id)) {
|
Optional<Allocation> allocation = allocationRepository.findById(new AllocationId(id, employeeId));
|
||||||
return ResponseEntity.notFound().build();
|
if (allocation.isEmpty()){
|
||||||
|
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||||
}
|
}
|
||||||
|
|
||||||
EmployeeResponseDTO employee;
|
allocationRepository.delete(allocation.get());
|
||||||
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);
|
|
||||||
}
|
|
||||||
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue