Skip to content

Commit

Permalink
Merge pull request #263 from sharemindteam/feature/262-comment-isWritten
Browse files Browse the repository at this point in the history
feat: 일대다 상담 댓글 조회 시 본인 작성 여부 필드 추가
  • Loading branch information
letskuku authored Oct 6, 2024
2 parents ede84b2 + 05eb505 commit 0e6713d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -41,7 +43,8 @@ public List<CommentGetResponse> 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();
}

Expand All @@ -58,12 +61,13 @@ public List<CommentGetResponse> 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();
}

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

0 comments on commit 0e6713d

Please sign in to comment.