From 20e896772bcec6ccde8d188008c16ad45e50f12f Mon Sep 17 00:00:00 2001 From: WooYoungDoo Date: Fri, 23 Feb 2024 22:08:39 +0900 Subject: [PATCH 1/4] =?UTF-8?q?feat=20:=20=ED=94=BC=EB=93=9C=EB=B0=B1=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1=EC=9E=90=20=EC=97=AC=EB=B6=80=20=ED=99=95?= =?UTF-8?q?=EC=9D=B8=20#42?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/sendback/domain/feedback/entity/Feedback.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/main/java/com/sendback/domain/feedback/entity/Feedback.java b/src/main/java/com/sendback/domain/feedback/entity/Feedback.java index f557ec2..66b6b99 100644 --- a/src/main/java/com/sendback/domain/feedback/entity/Feedback.java +++ b/src/main/java/com/sendback/domain/feedback/entity/Feedback.java @@ -13,6 +13,7 @@ import org.hibernate.annotations.SQLDelete; import java.time.LocalDate; +import java.util.Objects; @Entity @Getter @@ -78,4 +79,8 @@ public void updateIsFinished() { this.isFinished = true; } + public boolean isAuthor(final User user) { + return Objects.equals(this.user, user); + } + } From 7af7d80f8c99291fdf8ef73367cb6ffaaeabb7c2 Mon Sep 17 00:00:00 2001 From: WooYoungDoo Date: Fri, 23 Feb 2024 22:09:28 +0900 Subject: [PATCH 2/4] =?UTF-8?q?refactor=20:=20=ED=94=BC=EB=93=9C=EB=B0=B1?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=EC=9E=90=EA=B0=80=20=ED=94=BC=EB=93=9C?= =?UTF-8?q?=EB=B0=B1=20=EC=A0=9C=EC=B6=9C=20=EC=8B=9C=20=EC=98=88=EC=99=B8?= =?UTF-8?q?=20=EC=B2=98=EB=A6=AC=20#42?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../exception/FeedbackExceptionType.java | 3 ++- .../feedback/service/FeedbackService.java | 11 ++++++++-- .../feedback/service/FeedbackServiceTest.java | 20 +++++++++++++++++-- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/sendback/domain/feedback/exception/FeedbackExceptionType.java b/src/main/java/com/sendback/domain/feedback/exception/FeedbackExceptionType.java index 7fe5049..6b1ba9c 100644 --- a/src/main/java/com/sendback/domain/feedback/exception/FeedbackExceptionType.java +++ b/src/main/java/com/sendback/domain/feedback/exception/FeedbackExceptionType.java @@ -9,7 +9,8 @@ public enum FeedbackExceptionType implements ExceptionType { NOT_FOUND_FEEDBACK(3000, "요청한 피드백을 찾을 수 없습니다."), - DUPLICATE_FEEDBACK_SUBMIT(3010, "중복된 유저가 피드백을 제출했습니다."); + DUPLICATE_FEEDBACK_SUBMIT(3010, "중복된 유저가 피드백을 제출했습니다."), + REJECT_SUBMIT_FEEDBACK_BY_AUTHOR(3020, "작성자 본인은 본인 피드백에 제출할 수 없습니다."); private final int statusCode; private final String message; } diff --git a/src/main/java/com/sendback/domain/feedback/service/FeedbackService.java b/src/main/java/com/sendback/domain/feedback/service/FeedbackService.java index 0bee7c3..fd056af 100644 --- a/src/main/java/com/sendback/domain/feedback/service/FeedbackService.java +++ b/src/main/java/com/sendback/domain/feedback/service/FeedbackService.java @@ -21,8 +21,7 @@ import java.util.List; -import static com.sendback.domain.feedback.exception.FeedbackExceptionType.DUPLICATE_FEEDBACK_SUBMIT; -import static com.sendback.domain.feedback.exception.FeedbackExceptionType.NOT_FOUND_FEEDBACK; +import static com.sendback.domain.feedback.exception.FeedbackExceptionType.*; @Service @RequiredArgsConstructor @@ -89,6 +88,8 @@ public SubmitFeedbackResponseDto submitFeedback(Long userId, Long feedbackId, Mu User loginUser = userService.getUserById(userId); Feedback feedback = getFeedback(feedbackId); + validateIsAuthor(loginUser, feedback); + validateAlreadySubmit(loginUser, feedback); String screenShotUrl = imageService.uploadImage(file, "feedback"); @@ -102,6 +103,12 @@ public SubmitFeedbackResponseDto submitFeedback(Long userId, Long feedbackId, Mu return new SubmitFeedbackResponseDto(loginUser.getLevel().getName(), isLevelUp, remainCount); } + private void validateIsAuthor(User loginUser, Feedback feedback) { + boolean isAuthor = feedback.isAuthor(loginUser); + if (isAuthor) + throw new BadRequestException(REJECT_SUBMIT_FEEDBACK_BY_AUTHOR); + } + private boolean isLevelUpUserLevelBySubmitting(User user, Long submitCount) { Level level = Level.getLevelByFeedbackSubmitCount(submitCount); if (user.getLevel().equals(level)) diff --git a/src/test/java/com/sendback/domain/feedback/service/FeedbackServiceTest.java b/src/test/java/com/sendback/domain/feedback/service/FeedbackServiceTest.java index aa30577..b3c1358 100644 --- a/src/test/java/com/sendback/domain/feedback/service/FeedbackServiceTest.java +++ b/src/test/java/com/sendback/domain/feedback/service/FeedbackServiceTest.java @@ -26,8 +26,7 @@ import java.util.List; import java.util.Optional; -import static com.sendback.domain.feedback.exception.FeedbackExceptionType.DUPLICATE_FEEDBACK_SUBMIT; -import static com.sendback.domain.feedback.exception.FeedbackExceptionType.NOT_FOUND_FEEDBACK; +import static com.sendback.domain.feedback.exception.FeedbackExceptionType.*; import static com.sendback.domain.feedback.fixture.FeedbackFixture.*; import static com.sendback.domain.project.exception.ProjectExceptionType.NOT_PROJECT_AUTHOR; import static com.sendback.domain.project.fixture.ProjectFixture.createDummyProject; @@ -197,12 +196,27 @@ public void success() throws Exception { @DisplayName("피드백을 제출했을 때") class submitFeedback { + @Test + @DisplayName("작성자가 피드백을 제출하면 예외를 일으킨다.") + public void fail_isAuthor() throws Exception { + //given + given(userService.getUserById(anyLong())).willReturn(user); + given(feedbackRepository.findById(anyLong())).willReturn(Optional.of(feedback)); + given(feedback.isAuthor(any(User.class))).willReturn(true); + + //when - then + assertThatThrownBy(() -> feedbackService.submitFeedback(1L, 1L, mockingMultipartFile("screenShot"))) + .isInstanceOf(BadRequestException.class) + .hasMessage(REJECT_SUBMIT_FEEDBACK_BY_AUTHOR.getMessage()); + } + @Test @DisplayName("이미 제출했던 유저면 예외를 발생한다.") public void fail_alreadySubmit() throws Exception { //given given(userService.getUserById(anyLong())).willReturn(user); given(feedbackRepository.findById(anyLong())).willReturn(Optional.of(feedback)); + given(feedback.isAuthor(any(User.class))).willReturn(false); given(feedbackSubmitRepository.existsByUserAndFeedbackAndIsDeletedIsFalse(any(User.class), any(Feedback.class))).willReturn(true); //when - then @@ -217,6 +231,7 @@ public void success_keep() throws Exception { //given given(userService.getUserById(anyLong())).willReturn(user); given(feedbackRepository.findById(anyLong())).willReturn(Optional.of(feedback)); + given(feedback.isAuthor(any(User.class))).willReturn(false); given(feedbackSubmitRepository.existsByUserAndFeedbackAndIsDeletedIsFalse(any(User.class), any(Feedback.class))).willReturn(false); given(imageService.uploadImage(any(), anyString())).willReturn("sendback1.jpg"); given(feedbackSubmitRepository.save(any(FeedbackSubmit.class))).willReturn(feedbackSubmit); @@ -238,6 +253,7 @@ public void success_levelUp() throws Exception { //given given(userService.getUserById(anyLong())).willReturn(user); given(feedbackRepository.findById(anyLong())).willReturn(Optional.of(feedback)); + given(feedback.isAuthor(any(User.class))).willReturn(false); given(feedbackSubmitRepository.existsByUserAndFeedbackAndIsDeletedIsFalse(any(User.class), any(Feedback.class))).willReturn(false); given(imageService.uploadImage(any(), anyString())).willReturn("sendback1.jpg"); given(feedbackSubmitRepository.save(any(FeedbackSubmit.class))).willReturn(feedbackSubmit); From 0eeaab1fc51d2e5fa61293bb667f923023e3264a Mon Sep 17 00:00:00 2001 From: WooYoungDoo Date: Sat, 24 Feb 2024 00:24:09 +0900 Subject: [PATCH 3/4] =?UTF-8?q?refactor=20:=20=EC=BB=AC=EB=9F=BC=20length?= =?UTF-8?q?=20=EC=A1=B0=EC=A0=88=20#42?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/com/sendback/domain/feedback/entity/Feedback.java | 1 + src/main/java/com/sendback/domain/project/entity/Project.java | 1 + 2 files changed, 2 insertions(+) diff --git a/src/main/java/com/sendback/domain/feedback/entity/Feedback.java b/src/main/java/com/sendback/domain/feedback/entity/Feedback.java index 66b6b99..ef1076b 100644 --- a/src/main/java/com/sendback/domain/feedback/entity/Feedback.java +++ b/src/main/java/com/sendback/domain/feedback/entity/Feedback.java @@ -34,6 +34,7 @@ public class Feedback extends BaseEntity { private Project project; private String title; private String linkUrl; + @Column(length = 500) private String content; private String rewardMessage; private LocalDate startedAt; diff --git a/src/main/java/com/sendback/domain/project/entity/Project.java b/src/main/java/com/sendback/domain/project/entity/Project.java index 2543e64..1f4d061 100644 --- a/src/main/java/com/sendback/domain/project/entity/Project.java +++ b/src/main/java/com/sendback/domain/project/entity/Project.java @@ -42,6 +42,7 @@ public class Project extends BaseEntity { private String title; + @Column(length = 500) private String content; private String summary; From 65333da924ac7d54ebe5b1589c178133cfaa674e Mon Sep 17 00:00:00 2001 From: WooYoungDoo Date: Sat, 24 Feb 2024 02:31:44 +0900 Subject: [PATCH 4/4] =?UTF-8?q?fix=20:=20like,=20comment=20map=20->=20filt?= =?UTF-8?q?er=20=EA=B5=90=EC=B2=B4=20#42?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/project/dto/response/GetProjectsResponseDto.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/sendback/domain/project/dto/response/GetProjectsResponseDto.java b/src/main/java/com/sendback/domain/project/dto/response/GetProjectsResponseDto.java index 9c6e692..64b0b1e 100644 --- a/src/main/java/com/sendback/domain/project/dto/response/GetProjectsResponseDto.java +++ b/src/main/java/com/sendback/domain/project/dto/response/GetProjectsResponseDto.java @@ -31,8 +31,8 @@ public static GetProjectsResponseDto of(Project project, boolean isScrapped) { project.getFieldName().getName(), project.getCreatedAt(), project.getProjectPull().getPullUpCnt(), - project.getLikes().stream().map(like -> !like.isDeleted()).count(), - project.getComments().stream().map(comment -> !comment.isDeleted()).count(), + project.getLikes().stream().filter(like -> !like.isDeleted()).count(), + project.getComments().stream().filter(comment -> !comment.isDeleted()).count(), isScrapped ); }