diff --git a/resource-server/src/main/java/com/inhabas/api/domain/budget/dto/BudgetApplicationRegisterForm.java b/resource-server/src/main/java/com/inhabas/api/domain/budget/dto/BudgetApplicationRegisterForm.java index 901b9cb8..55d3f612 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/budget/dto/BudgetApplicationRegisterForm.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/budget/dto/BudgetApplicationRegisterForm.java @@ -8,6 +8,7 @@ import javax.validation.constraints.NotNull; import javax.validation.constraints.Past; import javax.validation.constraints.PositiveOrZero; +import javax.validation.constraints.Size; import lombok.AccessLevel; import lombok.Builder; @@ -39,6 +40,8 @@ public class BudgetApplicationRegisterForm { @NotBlank private String account; + @NotNull + @Size(min = 1) private List files = new ArrayList<>(); @Builder diff --git a/resource-server/src/main/java/com/inhabas/api/domain/club/dto/SaveClubActivityDto.java b/resource-server/src/main/java/com/inhabas/api/domain/club/dto/SaveClubActivityDto.java index 316d3ae2..8e677ec3 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/club/dto/SaveClubActivityDto.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/club/dto/SaveClubActivityDto.java @@ -4,6 +4,8 @@ import java.util.List; import javax.validation.constraints.NotBlank; +import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; import lombok.Builder; import lombok.Getter; @@ -17,6 +19,8 @@ public class SaveClubActivityDto { @NotBlank private String content; + @NotNull + @Size(min = 1) private List files = new ArrayList<>(); @Builder diff --git a/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDto.java b/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDto.java index 0181f8ae..86bab741 100644 --- a/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDto.java +++ b/resource-server/src/main/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDto.java @@ -7,6 +7,7 @@ import javax.validation.constraints.Future; import javax.validation.constraints.NotBlank; import javax.validation.constraints.NotNull; +import javax.validation.constraints.Size; import lombok.Builder; import lombok.Getter; @@ -50,6 +51,8 @@ public class SaveContestBoardDto { @Future(message = "이미 모집기간이 종료된 공모전은 등록할 수 없습니다.") private LocalDateTime dateContestEnd; + @NotNull + @Size(min = 1) private List files = new ArrayList<>(); @Builder diff --git a/resource-server/src/main/java/com/inhabas/api/web/ClubActivityController.java b/resource-server/src/main/java/com/inhabas/api/web/ClubActivityController.java index 7bd5573c..458b6090 100644 --- a/resource-server/src/main/java/com/inhabas/api/web/ClubActivityController.java +++ b/resource-server/src/main/java/com/inhabas/api/web/ClubActivityController.java @@ -3,6 +3,8 @@ import java.net.URI; import java.util.List; +import javax.validation.Valid; + import lombok.RequiredArgsConstructor; import org.springframework.data.domain.PageImpl; @@ -91,7 +93,7 @@ public ResponseEntity> getClubActivities( @PreAuthorize( "@boardSecurityChecker.checkMenuAccess(2, T(com.inhabas.api.domain.board.usecase.BoardSecurityChecker).CREATE_BOARD)") public ResponseEntity writeClubActivity( - @Authenticated Long memberId, @RequestBody SaveClubActivityDto form) { + @Authenticated Long memberId, @Valid @RequestBody SaveClubActivityDto form) { Long newClubActivityId = clubActivityService.writeClubActivity(memberId, form); URI location = ServletUriComponentsBuilder.fromCurrentRequest() @@ -168,7 +170,7 @@ public ResponseEntity findClubActivity(@PathVariable Long public ResponseEntity updateClubActivity( @Authenticated Long memberId, @PathVariable Long boardId, - @RequestBody SaveClubActivityDto form) { + @Valid @RequestBody SaveClubActivityDto form) { clubActivityService.updateClubActivity(boardId, form, memberId); return ResponseEntity.noContent().build(); } diff --git a/resource-server/src/test/java/com/inhabas/api/domain/club/dto/SaveClubActivityDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/club/dto/SaveClubActivityDtoTest.java index 51234bd9..468373bf 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/club/dto/SaveClubActivityDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/club/dto/SaveClubActivityDtoTest.java @@ -1,8 +1,8 @@ package com.inhabas.api.domain.club.dto; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.*; +import java.util.Arrays; import java.util.Set; import javax.validation.ConstraintViolation; @@ -36,7 +36,7 @@ public static void close() { public void validationTest() { // given SaveClubActivityDto saveClubActivityDto = - SaveClubActivityDto.builder().title("").content("").files(null).build(); + SaveClubActivityDto.builder().title("").content("").files(Arrays.asList("fileId")).build(); // when Set> violations = diff --git a/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDtoTest.java b/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDtoTest.java index 05eaeeb9..905e9b26 100644 --- a/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDtoTest.java +++ b/resource-server/src/test/java/com/inhabas/api/domain/contest/dto/SaveContestBoardDtoTest.java @@ -2,6 +2,7 @@ import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Set; @@ -37,7 +38,16 @@ public static void close() { public void FieldsAreNullError() { // given SaveContestBoardDto saveContestBoardDto = - new SaveContestBoardDto(null, null, null, null, null, null, null, null); + SaveContestBoardDto.builder() + .contestFieldId(null) + .title(null) + .content(null) + .association(null) + .topic(null) + .dateContestStart(null) + .dateContestEnd(null) + .files(null) + .build(); // when Set> violations = @@ -62,7 +72,16 @@ public void FieldsAreNullError() { public void FieldsAreBlankedError() { // given SaveContestBoardDto saveContestBoardDto = - new SaveContestBoardDto(null, " ", " ", " ", " ", null, null, null); + SaveContestBoardDto.builder() + .contestFieldId(null) + .title(" ") + .content(" ") + .association(" ") + .topic(" ") + .dateContestStart(null) + .dateContestEnd(null) + .files(Arrays.asList()) + .build(); // when Set> violations = @@ -87,15 +106,17 @@ public void FieldsAreBlankedError() { public void InputsAreExceededError() { // given SaveContestBoardDto saveContestBoardDto = - new SaveContestBoardDto( - 1L, - "title".repeat(20) + ".", - "content! Cucumber paste has to have a sun-dried, chilled sauerkraut component.", - "Assoc".repeat(20) + ".", - "topic".repeat(100) + ".", - LocalDateTime.of(2022, 1, 1, 0, 0, 0), - LocalDateTime.of(9999, 3, 3, 0, 0, 0), - null); + SaveContestBoardDto.builder() + .contestFieldId(1L) + .title("title".repeat(20) + ".") + .content( + "content! Cucumber paste has to have a sun-dried, chilled sauerkraut component.") + .association("Assoc".repeat(20) + ".") + .topic("topic".repeat(100) + ".") + .dateContestStart(LocalDateTime.of(2022, 1, 1, 0, 0, 0)) + .dateContestEnd(LocalDateTime.of(9999, 3, 3, 0, 0, 0)) + .files(Arrays.asList("fileId")) + .build(); // when Set> violations = @@ -115,15 +136,16 @@ public void InputsAreExceededError() { public void DeadlineIsOutdatedError() { // given SaveContestBoardDto saveContestBoardDto = - new SaveContestBoardDto( - 1L, - "title", - "content", - "association", - "topic", - LocalDateTime.of(2022, 1, 1, 0, 0, 0), - LocalDateTime.of(2022, 2, 1, 0, 0, 0), - null); + SaveContestBoardDto.builder() + .contestFieldId(1L) + .title("title") + .content("content") + .association("association") + .topic("topic") + .dateContestStart(LocalDateTime.of(2022, 1, 1, 0, 0, 0)) + .dateContestEnd(LocalDateTime.of(2022, 2, 1, 0, 0, 0)) + .files(Arrays.asList("fileId")) + .build(); // when Set> violations = diff --git a/resource-server/src/test/java/com/inhabas/api/web/BudgetApplicationControllerTest.java b/resource-server/src/test/java/com/inhabas/api/web/BudgetApplicationControllerTest.java index e74ad484..92c3bb2c 100644 --- a/resource-server/src/test/java/com/inhabas/api/web/BudgetApplicationControllerTest.java +++ b/resource-server/src/test/java/com/inhabas/api/web/BudgetApplicationControllerTest.java @@ -15,6 +15,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import java.time.LocalDateTime; +import java.util.Arrays; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; @@ -109,6 +110,7 @@ public void createApplicationTest_Success() throws Exception { .dateUsed(LocalDateTime.now()) .outcome(10000) .account("123-123-123") + .files(Arrays.asList("fileId")) .build(); given(budgetApplicationService.registerApplication(any(), any())).willReturn(1L); @@ -155,6 +157,7 @@ public void modifyApplicationTest_Success() throws Exception { .dateUsed(LocalDateTime.now()) .outcome(10000) .account("123-123-123") + .files(Arrays.asList("fileId")) .build(); doNothing().when(budgetApplicationService).updateApplication(any(), any(), any()); @@ -194,6 +197,7 @@ public void modifyApplicationTest_NotFound() throws Exception { .dateUsed(LocalDateTime.now()) .outcome(10000) .account("123-123-123") + .files(Arrays.asList("fileId")) .build(); doThrow(NotFoundException.class) .when(budgetApplicationService) diff --git a/resource-server/src/test/java/com/inhabas/api/web/ClubActivityControllerTest.java b/resource-server/src/test/java/com/inhabas/api/web/ClubActivityControllerTest.java index af5a0923..602b14f7 100644 --- a/resource-server/src/test/java/com/inhabas/api/web/ClubActivityControllerTest.java +++ b/resource-server/src/test/java/com/inhabas/api/web/ClubActivityControllerTest.java @@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets; import java.time.LocalDateTime; +import java.util.Arrays; import java.util.List; import org.springframework.beans.factory.annotation.Autowired; @@ -152,7 +153,12 @@ void findClubActivity_Not_Found() throws Exception { @Test void writeClubActivity() throws Exception { // given - SaveClubActivityDto form = new SaveClubActivityDto("title", "content", null); + SaveClubActivityDto form = + SaveClubActivityDto.builder() + .title("title") + .content("content") + .files(Arrays.asList("fileId")) + .build(); given(clubActivityService.writeClubActivity(any(), any())).willReturn(1L); // when @@ -175,7 +181,8 @@ void writeClubActivity() throws Exception { @Test void writeClubActivity_Invalid_Input() throws Exception { // given - SaveClubActivityDto form = new SaveClubActivityDto("", "", null); + SaveClubActivityDto form = + SaveClubActivityDto.builder().title("").content("").files(Arrays.asList()).build(); doThrow(InvalidInputException.class).when(clubActivityService).writeClubActivity(any(), any()); // when @@ -197,7 +204,13 @@ void writeClubActivity_Invalid_Input() throws Exception { @Test void updateClubActivity() throws Exception { // given - SaveClubActivityDto form = new SaveClubActivityDto("title", "content", null); + SaveClubActivityDto form = + SaveClubActivityDto.builder() + .title("title") + .content("content") + .files(Arrays.asList("fileId")) + .build(); + doNothing().when(clubActivityService).updateClubActivity(any(), any(), any()); // when then @@ -235,7 +248,12 @@ void updateClubActivity_Invalid_Input() throws Exception { @Test void updateClubActivity_Not_Found() throws Exception { // given - SaveClubActivityDto form = new SaveClubActivityDto("title", "content", null); + SaveClubActivityDto form = + SaveClubActivityDto.builder() + .title("title") + .content("content") + .files(Arrays.asList("fileId")) + .build(); doThrow(NotFoundException.class) .when(clubActivityService) diff --git a/resource-server/src/test/java/com/inhabas/api/web/ContestBoardControllerTest.java b/resource-server/src/test/java/com/inhabas/api/web/ContestBoardControllerTest.java index 6fa20a7b..1721c9fb 100644 --- a/resource-server/src/test/java/com/inhabas/api/web/ContestBoardControllerTest.java +++ b/resource-server/src/test/java/com/inhabas/api/web/ContestBoardControllerTest.java @@ -45,7 +45,6 @@ public class ContestBoardControllerTest { @Autowired private MockMvc mvc; - @Autowired private ObjectMapper objectMapper; @MockBean private ContestBoardService contestBoardService; @@ -213,6 +212,7 @@ void addBoard() throws Exception { .topic("good topic") .dateContestStart(LocalDateTime.now()) .dateContestEnd(LocalDateTime.now().plusDays(10)) + .files(List.of("fileId")) .build(); // when @@ -245,6 +245,7 @@ void addBoard_Invalid_Input() throws Exception { .topic("good topic") .dateContestStart(LocalDateTime.now()) .dateContestEnd(LocalDateTime.now().plusDays(10)) + .files(List.of("fileId")) .build(); String saveContestBoardDtoJson = objectMapper.writeValueAsString(saveContestBoardDto); @@ -280,6 +281,7 @@ void updateBoard() throws Exception { .topic("good topic") .dateContestStart(LocalDateTime.now()) .dateContestEnd(LocalDateTime.now().plusDays(10)) + .files(List.of("fileId")) .build(); // when then @@ -308,6 +310,7 @@ void updateBoard_Invalid_Input() throws Exception { .topic("good topic") .dateContestStart(LocalDateTime.now()) .dateContestEnd(LocalDateTime.now().plusDays(10)) + .files(List.of("fileId")) .build(); // when @@ -342,6 +345,7 @@ void updateBoard_Not_Found() throws Exception { .topic("good topic") .dateContestStart(LocalDateTime.now()) .dateContestEnd(LocalDateTime.now().plusDays(10)) + .files(List.of("fileId")) .build(); // when