Skip to content

Commit

Permalink
feat: (#321) 수정할 마감기한이 생성기한보다 3일 초과할 경우 예외 처리 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
tjdtls690 committed Aug 11, 2023
1 parent 9c5cbfa commit 3968a2f
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -283,4 +283,10 @@ private String getPostOptionImageUrl(
return postOptionImageUrls.get(postOptionIndex);
}

public void validateDeadLineToModify(final LocalDateTime deadlineToModify) {
if (getCreatedAt().plusDays(3).isBefore(deadlineToModify)) {
throw new BadRequestException(PostExceptionType.DEADLINE_EXCEED_THREE_DAYS);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public enum PostExceptionType implements ExceptionType {
POST_CLOSED(1004, "게시글이 이미 마감되었습니다."),
POST_NOT_HALF_DEADLINE(1005, "게시글이 마감 시간까지 절반의 시간 이상이 지나지 않으면 조기마감을 할 수 없습니다."),
NOT_VOTER(1004, "해당 게시글 작성자는 투표할 수 없습니다."),
DEADLINE_EXCEED_THREE_DAYS(1005, "마감 기한은 현재 시간으로부터 3일을 초과할 수 없습니다."),
DEADLINE_EXCEED_THREE_DAYS(1005, "마감 기한은 생성 시간으로부터 3일을 초과할 수 없습니다."),
WRONG_IMAGE(1006, "이미지 저장에 실패했습니다. 다시 시도해주세요."),
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public void update(
.orElseThrow(() -> new BadRequestException(PostExceptionType.POST_NOT_FOUND));
post.validateWriter(member);
post.validateDeadLine();
post.validateDeadLineToModify(request.deadline());


post.update(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1023,4 +1023,97 @@ void throwExceptionUpdateClosedPost() throws IOException {
.hasMessage(PostExceptionType.POST_CLOSED.getMessage());
}

@Test
@DisplayName("게시글 수정 시, 수정할 마감 기한이 생성 날짜보다 3일 초과면 예외를 던진다.")
void throwExceptionUpdateDeadlineOver() throws IOException {
// given
Category category1 = categoryRepository.save(CategoryFixtures.DEVELOP.get());
Member writer = memberRepository.save(MemberFixtures.MALE_20.get());

MockMultipartFile file1 = new MockMultipartFile(
"image1",
"test1.png",
"image/png",
new FileInputStream("src/test/resources/images/testImage1.PNG")
);
MockMultipartFile file2 = new MockMultipartFile(
"image2",
"test2.png",
"image/png",
new FileInputStream("src/test/resources/images/testImage2.PNG")
);

MockMultipartFile file3 = new MockMultipartFile(
"image3",
"test3.png",
"image/png",
new FileInputStream("src/test/resources/images/testImage3.PNG")
);

PostCreateRequest postCreateRequest = PostCreateRequest.builder()
.categoryIds(List.of(category1.getId()))
.title("title")
.content("content")
.postOptions(List.of(
PostOptionCreateRequest.builder()
.content("option1")
.build(),
PostOptionCreateRequest.builder()
.content("option2")
.build()
))
.deadline(LocalDateTime.now().plusDays(3))
.build();

Long savedPostId = postService.save(postCreateRequest, writer, List.of(file3), List.of(file1, file2));


Category category2 = categoryRepository.save(CategoryFixtures.FOOD.get());
MockMultipartFile file4 = new MockMultipartFile(
"image4",
"test4.png",
"image/png",
new FileInputStream("src/test/resources/images/testImage1.PNG")
);
MockMultipartFile file5 = new MockMultipartFile(
"image5",
"test5.png",
"image/png",
new FileInputStream("src/test/resources/images/testImage2.PNG")
);

MockMultipartFile file6 = new MockMultipartFile(
"image6",
"test6.png",
"image/png",
new FileInputStream("src/test/resources/images/testImage3.PNG")
);

PostUpdateRequest postUpdateRequest = PostUpdateRequest.builder()
.categoryIds(List.of(category2.getId()))
.title("title2")
.content("content2")
.postOptions(List.of(
PostOptionUpdateRequest.builder()
.content("option3")
.build(),
PostOptionUpdateRequest.builder()
.content("option4")
.build()
))
.deadline(LocalDateTime.now().plusDays(4))
.build();

// when, then
assertThatThrownBy(() -> postService.update(
savedPostId,
postUpdateRequest,
writer,
List.of(file4),
List.of(file5, file6)
))
.isInstanceOf(BadRequestException.class)
.hasMessage(PostExceptionType.DEADLINE_EXCEED_THREE_DAYS.getMessage());
}

}

0 comments on commit 3968a2f

Please sign in to comment.