From 2ca9cfbadb1dece1dd0860ba42276f71c1161ba8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20K=C3=BCck?= Date: Wed, 23 Oct 2024 11:11:58 +0200 Subject: [PATCH] PMT-27-code fix and cleanup Controller --- src/main/java/de/hmmh/pmt/ApiController.java | 21 ++++---------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index e4e8ac1..5d2a8f4 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -145,25 +145,12 @@ public class ApiController implements DefaultApi { @Override public ResponseEntity removeEmployeeFromProject(Long id, Long employeeId){ - if (!projectRepository.existsById(id)) { - return ResponseEntity.notFound().build(); + Optional 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); } }