From 21fb0f2c2a2b680b4592f42d1cd8e8657ef54d85 Mon Sep 17 00:00:00 2001 From: letskuku Date: Wed, 2 Oct 2024 00:00:37 +0900 Subject: [PATCH 1/2] =?UTF-8?q?#262=20feat:=20comment=20=EB=B3=B8=EC=9D=B8?= =?UTF-8?q?=20=EC=9E=91=EC=84=B1=20=EC=97=AC=EB=B6=80=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/dto/response/CommentGetResponse.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/example/sharemind/comment/dto/response/CommentGetResponse.java b/src/main/java/com/example/sharemind/comment/dto/response/CommentGetResponse.java index 37c7760b..a28e492f 100644 --- a/src/main/java/com/example/sharemind/comment/dto/response/CommentGetResponse.java +++ b/src/main/java/com/example/sharemind/comment/dto/response/CommentGetResponse.java @@ -36,9 +36,13 @@ public class CommentGetResponse { @Schema(description = "채택 여부", example = "true") private final Boolean isChosen; + @Schema(description = "조회한 회원의 작성 여부") + private final Boolean isWritten; + @Builder - public CommentGetResponse(Long commentId, Long counselorId, String nickName, String consultStyle, String content, - Boolean isLiked, Long totalLike, String updatedAt, Boolean isChosen) { + public CommentGetResponse(Long commentId, Long counselorId, String nickName, + String consultStyle, String content, Boolean isLiked, Long totalLike, String updatedAt, + Boolean isChosen, Boolean isWritten) { this.commentId = commentId; this.counselorId = counselorId; this.nickName = nickName; @@ -48,9 +52,10 @@ public CommentGetResponse(Long commentId, Long counselorId, String nickName, Str this.totalLike = totalLike; this.updatedAt = updatedAt; this.isChosen = isChosen; + this.isWritten = isWritten; } - public static CommentGetResponse of(Comment comment, Boolean isLiked) { + public static CommentGetResponse of(Comment comment, Boolean isLiked, Boolean isWritten) { return CommentGetResponse.builder() .commentId(comment.getCommentId()) .counselorId(comment.getCounselor().getCounselorId()) @@ -61,6 +66,7 @@ public static CommentGetResponse of(Comment comment, Boolean isLiked) { .totalLike(comment.getTotalLike()) .updatedAt(TimeUtil.getUpdatedAt(comment.getCreatedAt())) .isChosen(comment.getIsChosen()) + .isWritten(isWritten) .build(); } } From 05eb5053b6aae8c8681869b639b356ba357c9dcb Mon Sep 17 00:00:00 2001 From: letskuku Date: Wed, 2 Oct 2024 00:01:09 +0900 Subject: [PATCH 2/2] =?UTF-8?q?#262=20feat:=20CommentGetResponse=20dto?= =?UTF-8?q?=EC=97=90=20=EC=B6=94=EA=B0=80=EB=90=9C=20=ED=95=84=EB=93=9C?= =?UTF-8?q?=EA=B0=92=20=EB=84=A3=EB=8F=84=EB=A1=9D=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../comment/application/CommentServiceImpl.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/example/sharemind/comment/application/CommentServiceImpl.java b/src/main/java/com/example/sharemind/comment/application/CommentServiceImpl.java index 7975a9fe..ed768111 100644 --- a/src/main/java/com/example/sharemind/comment/application/CommentServiceImpl.java +++ b/src/main/java/com/example/sharemind/comment/application/CommentServiceImpl.java @@ -24,7 +24,9 @@ @Transactional(readOnly = true) @RequiredArgsConstructor public class CommentServiceImpl implements CommentService { + private static final Boolean COMMENT_IS_NOT_LIKED = false; + private static final Boolean COMMENT_IS_NOT_WRITTEN = false; private final PostService postService; private final CounselorService counselorService; @@ -41,7 +43,8 @@ public List getCounselorComments(Long postId, Long customerI return comments.stream() .map(comment -> CommentGetResponse.of(comment, commentLikeRepository.existsByCommentAndCustomerAndIsActivatedIsTrue( - comment, customer))) + comment, customer), + comment.getCounselor().equals(customer.getCounselor()))) .toList(); } @@ -58,12 +61,13 @@ public List getCustomerComments(Long postId, Long customerId return comments.stream() .map(comment -> CommentGetResponse.of(comment, commentLikeRepository.existsByCommentAndCustomerAndIsActivatedIsTrue( - comment, customer))) + comment, customer), COMMENT_IS_NOT_WRITTEN)) .toList(); } return comments.stream() - .map(comment -> CommentGetResponse.of(comment, COMMENT_IS_NOT_LIKED)) + .map(comment -> CommentGetResponse.of(comment, COMMENT_IS_NOT_LIKED, + COMMENT_IS_NOT_WRITTEN)) .toList(); } @@ -114,6 +118,7 @@ public Boolean getIsCommentOwner(Long postId, Long customerId) { Post post = postService.getPostByPostId(postId); Counselor counselor = counselorService.getCounselorByCustomerId(customerId); - return commentRepository.findByPostAndCounselorAndIsActivatedIsTrue(post, counselor) != null; + return commentRepository.findByPostAndCounselorAndIsActivatedIsTrue(post, counselor) + != null; } }