diff --git a/corn-backend/src/main/java/dev/corn/cornbackend/api/sprint/SprintControllerImpl.java b/corn-backend/src/main/java/dev/corn/cornbackend/api/sprint/SprintControllerImpl.java index 58fd56ab..b9807f0d 100644 --- a/corn-backend/src/main/java/dev/corn/cornbackend/api/sprint/SprintControllerImpl.java +++ b/corn-backend/src/main/java/dev/corn/cornbackend/api/sprint/SprintControllerImpl.java @@ -106,16 +106,16 @@ public final List getCurrentAndFutureSprints(@RequestParam long @Override @GetMapping(value = SPRINTS_AFTER_SPRINT) public final Page getSprintsAfterSprint(@RequestParam long sprintId, - Pageable pageable, - @JwtAuthed User user) { + Pageable pageable, + @JwtAuthed User user) { return sprintService.getSprintsAfterSprint(sprintId, pageable, user); } @Override @GetMapping(value = SPRINTS_BEFORE_SPRINT) public final Page getSprintsBeforeSprint(@RequestParam long sprintId, - Pageable pageable, - @JwtAuthed User user) { + Pageable pageable, + @JwtAuthed User user) { return sprintService.getSprintsBeforeSprint(sprintId, pageable, user); } diff --git a/corn-backend/src/main/java/dev/corn/cornbackend/api/sprint/SprintServiceImpl.java b/corn-backend/src/main/java/dev/corn/cornbackend/api/sprint/SprintServiceImpl.java index a74abd9f..df6c439b 100644 --- a/corn-backend/src/main/java/dev/corn/cornbackend/api/sprint/SprintServiceImpl.java +++ b/corn-backend/src/main/java/dev/corn/cornbackend/api/sprint/SprintServiceImpl.java @@ -139,7 +139,7 @@ public SprintResponse updateSprintsDescription(String description, long sprintId public SprintResponse updateSprintsStartDate(LocalDate startDate, long sprintId, User user) { log.info("Updating sprint with id: {} startDate to: {}", sprintId, startDate); - if (sprintRepository.existsSprintPeriodWithGivenDate(startDate)) { + if (sprintRepository.existsSprintPeriodWithGivenDate(startDate, sprintId)) { throw new InvalidSprintDateException("Start date cannot be after any existing sprint's end date"); } Sprint sprintToUpdate = sprintRepository.findByIdWithProjectOwner(sprintId, user) @@ -163,7 +163,7 @@ public SprintResponse updateSprintsStartDate(LocalDate startDate, long sprintId, public SprintResponse updateSprintsEndDate(LocalDate endDate, long sprintId, User user) { log.info("Updating sprint with id: {} endDate to: {}", sprintId, endDate); - if (sprintRepository.existsSprintPeriodWithGivenDate(endDate)) { + if (sprintRepository.existsSprintPeriodWithGivenDate(endDate, sprintId)) { throw new InvalidSprintDateException("End date cannot be before any existing sprint's end date"); } Sprint sprintToUpdate = sprintRepository.findByIdWithProjectOwner(sprintId, user) diff --git a/corn-backend/src/main/java/dev/corn/cornbackend/entities/sprint/interfaces/SprintRepository.java b/corn-backend/src/main/java/dev/corn/cornbackend/entities/sprint/interfaces/SprintRepository.java index e2ae51f2..864997e4 100644 --- a/corn-backend/src/main/java/dev/corn/cornbackend/entities/sprint/interfaces/SprintRepository.java +++ b/corn-backend/src/main/java/dev/corn/cornbackend/entities/sprint/interfaces/SprintRepository.java @@ -94,9 +94,9 @@ select count(s) > 0 from Sprint s */ @Query(""" select count(*) > 0 from Sprint s - where s.endDate <= :date and s.startDate >= :date + where s.endDate <= :date and s.startDate >= :date and s.sprintId != :sprintId """) - boolean existsSprintPeriodWithGivenDate(LocalDate date); + boolean existsSprintPeriodWithGivenDate(LocalDate date, long sprintId); /** * Finds all sprints with given project that have end date after specified date and pages them diff --git a/corn-backend/src/test/java/dev/corn/cornbackend/api/sprint/SprintServiceTest.java b/corn-backend/src/test/java/dev/corn/cornbackend/api/sprint/SprintServiceTest.java index 8e6f3de3..b198f302 100644 --- a/corn-backend/src/test/java/dev/corn/cornbackend/api/sprint/SprintServiceTest.java +++ b/corn-backend/src/test/java/dev/corn/cornbackend/api/sprint/SprintServiceTest.java @@ -453,7 +453,7 @@ final void test_updateSprintsStartDate_shouldThrowInvalidSprintDateException() { User owner = ADD_SPRINT_DATA.project().getOwner(); // when - when(sprintRepository.existsSprintPeriodWithGivenDate(newStartDate)) + when(sprintRepository.existsSprintPeriodWithGivenDate(newStartDate, sprintId)) .thenReturn(true); // then