diff --git a/src/main/java/com/example/asterbackend/domain/user/comment/presentation/response/QueryCommentResponse.java b/src/main/java/com/example/asterbackend/domain/user/comment/presentation/response/QueryCommentResponse.java index 616c8e4..88b01d5 100644 --- a/src/main/java/com/example/asterbackend/domain/user/comment/presentation/response/QueryCommentResponse.java +++ b/src/main/java/com/example/asterbackend/domain/user/comment/presentation/response/QueryCommentResponse.java @@ -20,13 +20,15 @@ public class QueryCommentResponse { private String commentWriterProfile; - public QueryCommentResponse(Comment comment) { + private boolean isLiked; + + public QueryCommentResponse(Comment comment, boolean commentLiked) { this.id = comment.getId(); this.commentContent = comment.getContent(); this.commentLikeCount = comment.getCommentLikeCount(); this.commentIsUpdated = comment.isUpdated(); this.commentWriter = comment.getUser().getUsername(); this.commentWriterProfile = comment.getUser().getProfileImgUrl(); - + this.isLiked = isLiked(); } } diff --git a/src/main/java/com/example/asterbackend/domain/user/comment/repository/CommentLikeRepository.java b/src/main/java/com/example/asterbackend/domain/user/comment/repository/CommentLikeRepository.java index af98204..3c0d32b 100644 --- a/src/main/java/com/example/asterbackend/domain/user/comment/repository/CommentLikeRepository.java +++ b/src/main/java/com/example/asterbackend/domain/user/comment/repository/CommentLikeRepository.java @@ -1,10 +1,14 @@ package com.example.asterbackend.domain.user.comment.repository; +import com.example.asterbackend.domain.user.comment.entity.Comment; import com.example.asterbackend.domain.user.comment.entity.CommentLike; +import com.example.asterbackend.domain.user.feed.entity.Feed; import org.springframework.data.jpa.repository.JpaRepository; public interface CommentLikeRepository extends JpaRepository { boolean existsByCommentIdAndStudentId(Long commentId, String studentId); + boolean existsByCommentAndStudentId(Comment comment, String studentId); + void deleteByCommentIdAndStudentId(Long commentId, String studentId); } diff --git a/src/main/java/com/example/asterbackend/domain/user/comment/service/comment/QueryCommentService.java b/src/main/java/com/example/asterbackend/domain/user/comment/service/comment/QueryCommentService.java index 14be7d6..80f6f5a 100644 --- a/src/main/java/com/example/asterbackend/domain/user/comment/service/comment/QueryCommentService.java +++ b/src/main/java/com/example/asterbackend/domain/user/comment/service/comment/QueryCommentService.java @@ -1,7 +1,9 @@ package com.example.asterbackend.domain.user.comment.service.comment; +import com.example.asterbackend.domain.user.comment.entity.Comment; import com.example.asterbackend.domain.user.comment.presentation.response.FeedAndCommentsResponse; import com.example.asterbackend.domain.user.comment.presentation.response.QueryCommentResponse; +import com.example.asterbackend.domain.user.comment.repository.CommentLikeRepository; import com.example.asterbackend.domain.user.comment.repository.CommentRepository; import com.example.asterbackend.domain.user.feed.entity.Feed; import com.example.asterbackend.domain.user.feed.facade.FeedFacade; @@ -26,18 +28,24 @@ public class QueryCommentService { private final UserFacade userFacade; + private final CommentLikeRepository commentLikeRepository; + + public FeedAndCommentsResponse queryComment(Long feedId) { Feed feed = feedFacade.currentFeed(feedId); - String studentId = userFacade.getStudentId(); boolean isLiked = likeRepository.existsByFeedAndStudentId(feed, studentId); + FeedListResponse feedResponse = new FeedListResponse(feed, isLiked); - FeedListResponse feedResponse = new FeedListResponse(feed,isLiked); + List allComments = commentRepository.findAllByFeedId(feedId); - List commentList = commentRepository.findAllByFeedId(feedId) + List commentList = allComments .stream() - .map(QueryCommentResponse::new) + .map(comment -> { + boolean commentLiked = commentLikeRepository.existsByCommentAndStudentId(comment, studentId); + return new QueryCommentResponse(comment, commentLiked); + }) .collect(Collectors.toList()); return new FeedAndCommentsResponse(feedResponse, commentList);