Skip to content

Commit

Permalink
🌨 :: CommentListResponse에 commentLiked 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyoil2 committed Dec 6, 2023
1 parent 9ff2fae commit 9c679cc
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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<CommentLike, Long> {
boolean existsByCommentIdAndStudentId(Long commentId, String studentId);

boolean existsByCommentAndStudentId(Comment comment, String studentId);

void deleteByCommentIdAndStudentId(Long commentId, String studentId);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Comment> allComments = commentRepository.findAllByFeedId(feedId);

List<QueryCommentResponse> commentList = commentRepository.findAllByFeedId(feedId)
List<QueryCommentResponse> 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);
Expand Down

0 comments on commit 9c679cc

Please sign in to comment.