From 8602cd949762122055c8228aeba4aaee00b1ca55 Mon Sep 17 00:00:00 2001 From: kkang_h00n Date: Sun, 20 Jul 2025 20:11:08 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Fix:=20=EC=95=A0=EC=99=84=20=EC=8B=9D?= =?UTF-8?q?=EB=AC=BC=20=EB=AC=BC=20=EC=A3=BC=EA=B8=B0=20=EB=B0=8F=20?= =?UTF-8?q?=EC=98=A4=EB=8A=98=EC=9D=98=20=EC=9D=BC=EA=B8=B0=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=EC=8B=9C,=20=EB=8B=B9=EC=9D=BC=20=EB=BF=90?= =?UTF-8?q?=EB=A7=8C=20=EC=95=84=EB=8B=8C=20=EC=9D=B4=EC=A0=84=20=EB=82=A0?= =?UTF-8?q?=EC=A7=9C=EB=8F=84=20=EC=9E=91=EC=84=B1=20=EA=B0=80=EB=8A=A5?= =?UTF-8?q?=ED=95=98=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../greening/petPlant/exception/PetPlantExceptionMessage.java | 2 +- .../greening/petPlant/service/DailyRecordCommandService.java | 3 ++- .../swyp/team5/greening/petPlant/service/WateringService.java | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/java/swyp/team5/greening/petPlant/exception/PetPlantExceptionMessage.java b/src/main/java/swyp/team5/greening/petPlant/exception/PetPlantExceptionMessage.java index dfa0d6c..16920ef 100644 --- a/src/main/java/swyp/team5/greening/petPlant/exception/PetPlantExceptionMessage.java +++ b/src/main/java/swyp/team5/greening/petPlant/exception/PetPlantExceptionMessage.java @@ -14,7 +14,7 @@ public enum PetPlantExceptionMessage implements ExceptionMessage { NOT_FOUND_DAILY_RECORD("해당 날짜의 기록이 존재하지 않습니다.", "404"), ALREADY_EXISTS_DAILY_RECORD("이미 작성한 오늘의 기록이 존재합니다", "409"), - INVALID_DATE_ACCESS("해당 날짜에만 접근 가능합니다.", "400"); + INVALID_DATE_ACCESS("해당 날짜에 미리 접근할 수 없습니다.", "400"); private final String message; private final String code; diff --git a/src/main/java/swyp/team5/greening/petPlant/service/DailyRecordCommandService.java b/src/main/java/swyp/team5/greening/petPlant/service/DailyRecordCommandService.java index 4bd294a..95b9002 100644 --- a/src/main/java/swyp/team5/greening/petPlant/service/DailyRecordCommandService.java +++ b/src/main/java/swyp/team5/greening/petPlant/service/DailyRecordCommandService.java @@ -54,7 +54,8 @@ public CreateDailyRecordResponseDto createDailyRecord( } //3 - if (!Objects.equals(nowDate.get(), requestDto.today())) { + //현재 시간 < 요청으로 들어온 시간 + if (nowDate.get().isBefore(requestDto.today())) { throw new GreeningGlobalException(PetPlantExceptionMessage.INVALID_DATE_ACCESS); } diff --git a/src/main/java/swyp/team5/greening/petPlant/service/WateringService.java b/src/main/java/swyp/team5/greening/petPlant/service/WateringService.java index 8cddffc..951b396 100644 --- a/src/main/java/swyp/team5/greening/petPlant/service/WateringService.java +++ b/src/main/java/swyp/team5/greening/petPlant/service/WateringService.java @@ -45,7 +45,7 @@ public WateringPlantResponseDto wateringPlant( PetPlantExceptionMessage.BAD_REQUEST_PET_PLANT_WRITER); } - if (!Objects.equals(nowDate.get(), today)) { + if (nowDate.get().isBefore(today)) { throw new GreeningGlobalException(PetPlantExceptionMessage.INVALID_DATE_ACCESS); } From f5cd9617f2b212937313656ed13131500893bc99 Mon Sep 17 00:00:00 2001 From: kkang_h00n Date: Sun, 20 Jul 2025 20:22:47 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Test:=20=EC=95=A0=EC=99=84=20=EC=8B=9D?= =?UTF-8?q?=EB=AC=BC=20=EB=AC=BC=20=EC=A3=BC=EA=B8=B0=20=EB=B0=8F=20?= =?UTF-8?q?=EC=98=A4=EB=8A=98=EC=9D=98=20=EC=9D=BC=EA=B8=B0=20=EC=9E=91?= =?UTF-8?q?=EC=84=B1=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=8B=9C,=20?= =?UTF-8?q?=EB=82=A0=EC=A7=9C=EC=97=90=20=EB=8C=80=ED=95=9C=20=EC=A1=B0?= =?UTF-8?q?=EA=B1=B4=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/DailyRecordControllerTest.java | 8 ++++---- .../service/DailyRecordCommandServiceTest.java | 6 ++++-- .../petPlant/service/WateringServiceTest.java | 14 ++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/test/java/swyp/team5/greening/petPlant/controller/DailyRecordControllerTest.java b/src/test/java/swyp/team5/greening/petPlant/controller/DailyRecordControllerTest.java index 18fbe7c..f255a3c 100644 --- a/src/test/java/swyp/team5/greening/petPlant/controller/DailyRecordControllerTest.java +++ b/src/test/java/swyp/team5/greening/petPlant/controller/DailyRecordControllerTest.java @@ -60,7 +60,7 @@ class TestCase1 { LocalDate now = LocalDate.of(2025, 7, 3); - LocalDate future = LocalDate.of(2025, 7, 5); + LocalDate past = LocalDate.of(2025, 7, 2); String title = "제목"; @@ -138,10 +138,10 @@ void createDailyRecord2() throws Exception { } @Test - @DisplayName("오늘이 아닌 날짜에 대해 오늘의 기록을 작성할 수 없다.") + @DisplayName("오늘보다 이후 날짜에 대해 오늘의 기록을 작성할 수 없다.") void createDailyRecord3() throws Exception { //given - given(nowDate.get()).willReturn(future); + given(nowDate.get()).willReturn(past); //when ResultActions perform = mockMvc.perform( @@ -213,4 +213,4 @@ void getDailyRecord1() throws Exception { } } -} \ No newline at end of file +} diff --git a/src/test/java/swyp/team5/greening/petPlant/service/DailyRecordCommandServiceTest.java b/src/test/java/swyp/team5/greening/petPlant/service/DailyRecordCommandServiceTest.java index 0e18f4e..0d98d55 100644 --- a/src/test/java/swyp/team5/greening/petPlant/service/DailyRecordCommandServiceTest.java +++ b/src/test/java/swyp/team5/greening/petPlant/service/DailyRecordCommandServiceTest.java @@ -122,12 +122,14 @@ void createDailyRecord2() { } @Test - @DisplayName("오늘이 아닌 날짜에 대해 오늘의 기록을 작성할 수 없다.") + @DisplayName("오늘보다 이후 날짜에 대해 오늘의 기록을 작성할 수 없다.") void createDailyRecord3() { //given List contents = List.of( new DailyRecordContentDto("TEXT", content)); + given(now.get()).willReturn(nowDate); + //when ThrowingCallable throwingCallable = () -> dailyRecordCommandService.createDailyRecord( userId, petPlant.getId(), @@ -141,4 +143,4 @@ void createDailyRecord3() { } } -} \ No newline at end of file +} diff --git a/src/test/java/swyp/team5/greening/petPlant/service/WateringServiceTest.java b/src/test/java/swyp/team5/greening/petPlant/service/WateringServiceTest.java index 3f330db..3e735e1 100644 --- a/src/test/java/swyp/team5/greening/petPlant/service/WateringServiceTest.java +++ b/src/test/java/swyp/team5/greening/petPlant/service/WateringServiceTest.java @@ -51,7 +51,7 @@ class TestCase1 { private final String type = "민들레"; private final LocalDate nowDate = LocalDate.of(2025,7,3); - private final LocalDate future = LocalDate.of(2030,8,16); + private final LocalDate future = LocalDate.of(2026,8,16); private PetPlant petPlant; @@ -87,7 +87,7 @@ void wateringPlantTest() { userId, petPlant.getId(), nowDate); //then - assertThat(1L).isEqualTo(result.wateringId()); + assertThat(result.wateringId()).isEqualTo(1L); verify(wateringRepository, times(1)).save(any(Watering.class)); } @@ -105,14 +105,14 @@ void wateringPlantTest2() { } @Test - @DisplayName("오늘이 아닌 날짜의 물을 줄 수 없다.") + @DisplayName("오늘보다 이후 날짜의 물을 줄 수 없다.") void wateringPlantTest3() { //given - given(now.get()).willReturn(future); + given(now.get()).willReturn(nowDate); //when ThrowingCallable throwingCallable = () -> wateringService.wateringPlant( - userId, petPlant.getId(), nowDate); + userId, petPlant.getId(), future); //then assertThatThrownBy(throwingCallable) @@ -120,6 +120,4 @@ void wateringPlantTest3() { .hasMessage(PetPlantExceptionMessage.INVALID_DATE_ACCESS.getMessage()); } } - - -} \ No newline at end of file +}