Skip to content

Commit 6bee45f

Browse files
authored
Merge pull request #104 from SWYP-9th-Team5/103/Fix
Fix: 애완 식물 물 주기 및 오늘의 일기 작성 시, 당일 뿐만 아닌 이전 날짜도 작성 가능하도록 수정
2 parents ffa750c + f5cd961 commit 6bee45f

6 files changed

Lines changed: 18 additions & 17 deletions

File tree

src/main/java/swyp/team5/greening/petPlant/exception/PetPlantExceptionMessage.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ public enum PetPlantExceptionMessage implements ExceptionMessage {
1414
NOT_FOUND_DAILY_RECORD("해당 날짜의 기록이 존재하지 않습니다.", "404"),
1515
ALREADY_EXISTS_DAILY_RECORD("이미 작성한 오늘의 기록이 존재합니다", "409"),
1616

17-
INVALID_DATE_ACCESS("해당 날짜에만 접근 가능합니다.", "400");
17+
INVALID_DATE_ACCESS("해당 날짜에 미리 접근할 수 없습니다.", "400");
1818

1919
private final String message;
2020
private final String code;

src/main/java/swyp/team5/greening/petPlant/service/DailyRecordCommandService.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ public CreateDailyRecordResponseDto createDailyRecord(
5454
}
5555

5656
//3
57-
if (!Objects.equals(nowDate.get(), requestDto.today())) {
57+
//현재 시간 < 요청으로 들어온 시간
58+
if (nowDate.get().isBefore(requestDto.today())) {
5859
throw new GreeningGlobalException(PetPlantExceptionMessage.INVALID_DATE_ACCESS);
5960
}
6061

src/main/java/swyp/team5/greening/petPlant/service/WateringService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public WateringPlantResponseDto wateringPlant(
4545
PetPlantExceptionMessage.BAD_REQUEST_PET_PLANT_WRITER);
4646
}
4747

48-
if (!Objects.equals(nowDate.get(), today)) {
48+
if (nowDate.get().isBefore(today)) {
4949
throw new GreeningGlobalException(PetPlantExceptionMessage.INVALID_DATE_ACCESS);
5050
}
5151

src/test/java/swyp/team5/greening/petPlant/controller/DailyRecordControllerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class TestCase1 {
6060

6161
LocalDate now = LocalDate.of(2025, 7, 3);
6262

63-
LocalDate future = LocalDate.of(2025, 7, 5);
63+
LocalDate past = LocalDate.of(2025, 7, 2);
6464

6565
String title = "제목";
6666

@@ -138,10 +138,10 @@ void createDailyRecord2() throws Exception {
138138
}
139139

140140
@Test
141-
@DisplayName("오늘이 아닌 날짜에 대해 오늘의 기록을 작성할 수 없다.")
141+
@DisplayName("오늘보다 이후 날짜에 대해 오늘의 기록을 작성할 수 없다.")
142142
void createDailyRecord3() throws Exception {
143143
//given
144-
given(nowDate.get()).willReturn(future);
144+
given(nowDate.get()).willReturn(past);
145145

146146
//when
147147
ResultActions perform = mockMvc.perform(
@@ -213,4 +213,4 @@ void getDailyRecord1() throws Exception {
213213
}
214214
}
215215

216-
}
216+
}

src/test/java/swyp/team5/greening/petPlant/service/DailyRecordCommandServiceTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,14 @@ void createDailyRecord2() {
122122
}
123123

124124
@Test
125-
@DisplayName("오늘이 아닌 날짜에 대해 오늘의 기록을 작성할 수 없다.")
125+
@DisplayName("오늘보다 이후 날짜에 대해 오늘의 기록을 작성할 수 없다.")
126126
void createDailyRecord3() {
127127
//given
128128
List<DailyRecordContentDto> contents = List.of(
129129
new DailyRecordContentDto("TEXT", content));
130130

131+
given(now.get()).willReturn(nowDate);
132+
131133
//when
132134
ThrowingCallable throwingCallable = () -> dailyRecordCommandService.createDailyRecord(
133135
userId, petPlant.getId(),
@@ -141,4 +143,4 @@ void createDailyRecord3() {
141143
}
142144
}
143145

144-
}
146+
}

src/test/java/swyp/team5/greening/petPlant/service/WateringServiceTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class TestCase1 {
5151
private final String type = "민들레";
5252

5353
private final LocalDate nowDate = LocalDate.of(2025,7,3);
54-
private final LocalDate future = LocalDate.of(2030,8,16);
54+
private final LocalDate future = LocalDate.of(2026,8,16);
5555

5656
private PetPlant petPlant;
5757

@@ -87,7 +87,7 @@ void wateringPlantTest() {
8787
userId, petPlant.getId(), nowDate);
8888

8989
//then
90-
assertThat(1L).isEqualTo(result.wateringId());
90+
assertThat(result.wateringId()).isEqualTo(1L);
9191
verify(wateringRepository, times(1)).save(any(Watering.class));
9292
}
9393

@@ -105,21 +105,19 @@ void wateringPlantTest2() {
105105
}
106106

107107
@Test
108-
@DisplayName("오늘이 아닌 날짜의 물을 줄 수 없다.")
108+
@DisplayName("오늘보다 이후 날짜의 물을 줄 수 없다.")
109109
void wateringPlantTest3() {
110110
//given
111-
given(now.get()).willReturn(future);
111+
given(now.get()).willReturn(nowDate);
112112

113113
//when
114114
ThrowingCallable throwingCallable = () -> wateringService.wateringPlant(
115-
userId, petPlant.getId(), nowDate);
115+
userId, petPlant.getId(), future);
116116

117117
//then
118118
assertThatThrownBy(throwingCallable)
119119
.isInstanceOf(GreeningGlobalException.class)
120120
.hasMessage(PetPlantExceptionMessage.INVALID_DATE_ACCESS.getMessage());
121121
}
122122
}
123-
124-
125-
}
123+
}

0 commit comments

Comments
 (0)