Skip to content

Commit 2382a55

Browse files
authored
Fix: 날짜 정보 형식 오류 수정 (#154) (#160)
* fix: 날짜 형식 제한 삭제.dto에서 자동 초단위로 절삭 * fix: 초단위 절삭에서 분단위 절삭으로 수정 * test: 케이스 추가 및 변경사항 적용 확인
1 parent f280430 commit 2382a55

File tree

3 files changed

+54
-10
lines changed

3 files changed

+54
-10
lines changed

src/main/java/com/back/domain/study/plan/dto/StudyPlanRequest.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,41 @@
1010
import lombok.Setter;
1111

1212
import java.time.LocalDateTime;
13+
import java.time.temporal.ChronoUnit;
1314
import java.util.ArrayList;
1415
import java.util.List;
1516

1617
@Getter
1718
@Setter
1819
@NoArgsConstructor
19-
@AllArgsConstructor
2020
public class StudyPlanRequest {
2121
private String subject;
2222

23-
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
2423
private LocalDateTime startDate;
2524

26-
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss")
2725
private LocalDateTime endDate;
2826

2927
private Color color;
3028

3129
// RepeatRule 중첩 객체
3230
private RepeatRuleRequest repeatRule;
31+
// LocalDateTime을 분 단위로 자르기 위한 setter
32+
public void setStartDate(LocalDateTime startDate) {
33+
this.startDate = startDate != null ? startDate.truncatedTo(ChronoUnit.MINUTES) : null;
34+
}
35+
public void setEndDate(LocalDateTime endDate) {
36+
this.endDate = endDate != null ? endDate.truncatedTo(ChronoUnit.MINUTES) : null;
37+
}
38+
39+
// 분 단위로 자른 값을 생성자에서도 설정
40+
public StudyPlanRequest(String subject, LocalDateTime startDate, LocalDateTime endDate,
41+
Color color, RepeatRuleRequest repeatRule) {
42+
this.subject = subject;
43+
this.startDate = startDate != null ? startDate.truncatedTo(ChronoUnit.MINUTES) : null;
44+
this.endDate = endDate != null ? endDate.truncatedTo(ChronoUnit.MINUTES) : null;
45+
this.color = color;
46+
this.repeatRule = repeatRule;
47+
}
3348

3449
@Getter
3550
@Setter

src/main/java/com/back/global/exception/GlobalExceptionHandler.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ public ResponseEntity<RsData<Void>> handleValidationException(MethodArgumentNotV
3434
.body(RsData.fail(ErrorCode.BAD_REQUEST));
3535
}
3636

37-
// PATH VARIABLE, REQUEST PARAMETER 타입 미스매치 예외 처리
38-
// 클라이언트의 데이터 형식이 서버 인자 타입과 안 맞는 경우 예외 (형식 불일치)
37+
// PATH VARIABLE, REQUEST PARAMETER의 validation 예외 처리
38+
// 클라이언트의 데이터 형식이 서버 인자 형식과 안 맞는 경우 예외 (형식 불일치)
3939
@ExceptionHandler(MethodArgumentTypeMismatchException.class)
4040
@ResponseStatus(HttpStatus.BAD_REQUEST)
4141
public ResponseEntity<RsData<Void>> handleMethodArgumentTypeMismatch(MethodArgumentTypeMismatchException ex) {

src/test/java/com/back/domain/study/plan/controller/StudyPlanControllerTest.java

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ private StudyPlan createDailyPlan() {
135135
}
136136

137137
@Test
138-
@DisplayName("단발성 계획 생성")
138+
@DisplayName("단발성 계획 생성 - 하나에만 밀리초가 들어가도 되는가?!")
139139
void t1() throws Exception {
140140

141141
ResultActions resultActions = mvc.perform(post("/api/plans")
@@ -144,8 +144,8 @@ void t1() throws Exception {
144144
.content("""
145145
{
146146
"subject": "단발성 계획",
147-
"startDate": "2025-09-26T10:46:00",
148-
"endDate": "2025-09-26T11:46:00",
147+
"startDate": "2025-10-03T17:00:00",
148+
"endDate": "2025-10-03T18:30:00.000",
149149
"color": "RED"
150150
}
151151
"""))
@@ -162,8 +162,37 @@ void t1() throws Exception {
162162
.andExpect(jsonPath("$.message").value("학습 계획이 성공적으로 생성되었습니다."))
163163
.andExpect(jsonPath("$.data.subject").value("단발성 계획"))
164164
.andExpect(jsonPath("$.data.color").value("RED"))
165-
.andExpect(jsonPath("$.data.startDate").value("2025-09-26T10:46:00"))
166-
.andExpect(jsonPath("$.data.endDate").value("2025-09-26T11:46:00"))
165+
.andExpect(jsonPath("$.data.startDate").value("2025-10-03T17:00:00"))
166+
.andExpect(jsonPath("$.data.endDate").value("2025-10-03T18:30:00"))
167+
.andExpect(jsonPath("$.data.repeatRule").doesNotExist());
168+
169+
}
170+
171+
@Test
172+
@DisplayName("단발성 계획 생성 - 밀리초까지도 둘 다 전송받는 경우")
173+
void t1_1() throws Exception {
174+
175+
ResultActions resultActions = mvc.perform(post("/api/plans")
176+
.header("Authorization", "Bearer faketoken")
177+
.contentType(MediaType.APPLICATION_JSON)
178+
.content("""
179+
{
180+
"subject": "단발성 계획 - 밀리초 포함",
181+
"startDate": "2025-09-21T05:00:00.000",
182+
"endDate": "2025-09-21T07:00:00.000",
183+
"color": "RED"
184+
}
185+
"""))
186+
.andDo(print());
187+
188+
resultActions
189+
.andExpect(status().isOk()) // 200 OK인지 확인
190+
.andExpect(handler().handlerType(StudyPlanController.class))
191+
.andExpect(handler().methodName("createStudyPlan"))
192+
.andExpect(jsonPath("$.success").value(true))
193+
.andExpect(jsonPath("$.message").value("학습 계획이 성공적으로 생성되었습니다."))
194+
.andExpect(jsonPath("$.data.startDate").value("2025-09-21T05:00:00"))
195+
.andExpect(jsonPath("$.data.endDate").value("2025-09-21T07:00:00"))
167196
.andExpect(jsonPath("$.data.repeatRule").doesNotExist());
168197

169198
}

0 commit comments

Comments
 (0)