diff --git a/src/main/java/com/example/codebase/domain/exhibition/dto/EventScheduleCreateDTO.java b/src/main/java/com/example/codebase/domain/exhibition/dto/EventScheduleCreateDTO.java index 1ac2c131..ef6842cb 100644 --- a/src/main/java/com/example/codebase/domain/exhibition/dto/EventScheduleCreateDTO.java +++ b/src/main/java/com/example/codebase/domain/exhibition/dto/EventScheduleCreateDTO.java @@ -30,8 +30,14 @@ public class EventScheduleCreateDTO { private List participants; public void checkTimeValidity() { + if (this.endDateTime == null) { + return; + } if (this.startDateTime.equals(this.endDateTime)) { throw new RuntimeException("시작시간과 종료시간이 같을 수 없습니다."); } + if (this.startDateTime.isAfter(this.endDateTime)) { + throw new RuntimeException("시작시간이 종료시간보다 늦을 수 없습니다."); + } } } diff --git a/src/test/java/com/example/codebase/controller/ExhibitionControllerTest.java b/src/test/java/com/example/codebase/controller/ExhibitionControllerTest.java index bda5daf0..fe3605c5 100644 --- a/src/test/java/com/example/codebase/controller/ExhibitionControllerTest.java +++ b/src/test/java/com/example/codebase/controller/ExhibitionControllerTest.java @@ -397,7 +397,7 @@ private byte[] createImageFile() throws IOException { .accept(MediaType.APPLICATION_JSON) .characterEncoding("UTF-8")) .andDo(print()) - .andExpect(status().isCreated()); + .andExpect(status().isBadRequest()); } @DisplayName("이벤트 전체 조회 - 성공") @@ -703,4 +703,37 @@ private byte[] createImageFile() throws IOException { .andExpect(status().isBadRequest()); } + @WithMockCustomUser(username = "user", role = "CURATOR") + @DisplayName("스케줄 종료시간이 시작시간보다 빠를시") + @Test + public void 스케줄_생성시_종료시간이_시작시간보다_빠른경우() throws Exception { + createOrLoadMember("user", RoleStatus.CURATOR, "ROLE_CURATOR"); + + ExhbitionCreateDTO dto = mockCreateExhibitionDTO(1); + EventScheduleCreateDTO eventScheduleCreateDTO = dto.getSchedule().get(0); + eventScheduleCreateDTO.setEndDateTime(LocalDateTime.now().minusHours(1)); + eventScheduleCreateDTO.setStartDateTime(LocalDateTime.now()); + + MockMultipartFile dtoFile = + new MockMultipartFile("dto", "", "application/json", objectMapper.writeValueAsBytes(dto)); + + MockMultipartFile mediaFile = + new MockMultipartFile("mediaFiles", "image.jpg", "image/jpg", createImageFile()); + + MockMultipartFile thumbnailFile = + new MockMultipartFile("thumbnailFile", "image.jpg", "image/jpg", createImageFile()); + + mockMvc + .perform( + multipart("/api/exhibitions") + .file(dtoFile) + .file(mediaFile) + .file(thumbnailFile) + .contentType(MediaType.MULTIPART_FORM_DATA) + .accept(MediaType.APPLICATION_JSON) + .characterEncoding("UTF-8")) + .andDo(print()) + .andExpect(status().isBadRequest()); + } + }