Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bugfix/#344] 첨부파일이 필요한 게시판에서 생성, 수정할 때 첨부파일 빈 값으로 보내는 경우 검증로직 추가 #345

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -39,6 +40,8 @@ public class BudgetApplicationRegisterForm {

@NotBlank private String account;

@NotNull
@Size(min = 1)
private List<String> files = new ArrayList<>();

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +19,8 @@ public class SaveClubActivityDto {

@NotBlank private String content;

@NotNull
@Size(min = 1)
private List<String> files = new ArrayList<>();

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -50,6 +51,8 @@ public class SaveContestBoardDto {
@Future(message = "이미 모집기간이 종료된 공모전은 등록할 수 없습니다.")
private LocalDateTime dateContestEnd;

@NotNull
@Size(min = 1)
private List<String> files = new ArrayList<>();

@Builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -91,7 +93,7 @@ public ResponseEntity<PagedResponseDto<ClubActivityDto>> getClubActivities(
@PreAuthorize(
"@boardSecurityChecker.checkMenuAccess(2, T(com.inhabas.api.domain.board.usecase.BoardSecurityChecker).CREATE_BOARD)")
public ResponseEntity<Void> writeClubActivity(
@Authenticated Long memberId, @RequestBody SaveClubActivityDto form) {
@Authenticated Long memberId, @Valid @RequestBody SaveClubActivityDto form) {
Long newClubActivityId = clubActivityService.writeClubActivity(memberId, form);
URI location =
ServletUriComponentsBuilder.fromCurrentRequest()
Expand Down Expand Up @@ -168,7 +170,7 @@ public ResponseEntity<ClubActivityDetailDto> findClubActivity(@PathVariable Long
public ResponseEntity<ClubActivityDto> updateClubActivity(
@Authenticated Long memberId,
@PathVariable Long boardId,
@RequestBody SaveClubActivityDto form) {
@Valid @RequestBody SaveClubActivityDto form) {
clubActivityService.updateClubActivity(boardId, form, memberId);
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<ConstraintViolation<SaveClubActivityDto>> violations =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;

Expand Down Expand Up @@ -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<ConstraintViolation<SaveContestBoardDto>> violations =
Expand All @@ -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<ConstraintViolation<SaveContestBoardDto>> violations =
Expand All @@ -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<ConstraintViolation<SaveContestBoardDto>> violations =
Expand All @@ -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<ConstraintViolation<SaveContestBoardDto>> violations =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
public class ContestBoardControllerTest {

@Autowired private MockMvc mvc;

@Autowired private ObjectMapper objectMapper;

@MockBean private ContestBoardService contestBoardService;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading