diff --git a/src/main/java/de/hmmh/pmt/ApiController.java b/src/main/java/de/hmmh/pmt/ApiController.java index f2a736f..b201393 100644 --- a/src/main/java/de/hmmh/pmt/ApiController.java +++ b/src/main/java/de/hmmh/pmt/ApiController.java @@ -100,43 +100,36 @@ public class ApiController implements DefaultApi { public ResponseEntity addEmployee(Long id, AddEmployeeDTO body) { Optional optionalProject = projectRepository.findById(id); - - if (projectRepository.findById(id).isEmpty()) { + if (optionalProject.isEmpty()) { return new ResponseEntity<>(HttpStatus.NOT_FOUND); } Project project = optionalProject.get(); EmployeeResponseDTO employee; try { - employee = apiClientFactory.getEmployeeApi().findById(body.getEmployeeId()); + employee = apiClientFactory.getEmployeeApi().findById(body.getEmployeeId()); } catch (HttpClientErrorException exception) { return new ResponseEntity<>(exception.getStatusCode().equals(HttpStatus.NOT_FOUND) ? HttpStatus.NOT_FOUND : HttpStatus.INTERNAL_SERVER_ERROR); } - boolean hasQualification = employee.getSkillSet() + if (employee.getSkillSet() .stream() - .anyMatch(qualification -> qualification.getId().equals(body.getQualificationId())); - - if (!hasQualification) { + .anyMatch(qualification -> qualification.getId().equals(body.getQualificationId()))) { return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY); } long start = project.getStart().toEpochSecond(null); long plannedEnd = project.getPlannedEnd().toEpochSecond(null); - List allocations = allocationRepository.findAllocationsByEmployeeId(body.getEmployeeId()); - - boolean hasOverlap = allocations.stream() + if (allocations.stream() .map(Allocation::getProject) .anyMatch(allocatedProject -> { long allocatedStart = allocatedProject.getStart().toEpochSecond(null); long allocatedPlannedEnd = allocatedProject.getPlannedEnd().toEpochSecond(null); return Math.max(start, allocatedStart) <= Math.min(plannedEnd, allocatedPlannedEnd); - }); - - if (hasOverlap) { + })) { return new ResponseEntity<>(HttpStatus.UNPROCESSABLE_ENTITY); }