Skip to content

Commit

Permalink
Feat: 게시글 Detail 반환 시 좋아요 여부 필드 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
chaejm55 committed Oct 21, 2024
1 parent 8366001 commit f00e4cc
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ public static class Detail {
private int sharedCount;
private boolean canDelete;
private boolean canModify;
private boolean isLiked;

public static Detail from(Post post, AccessModel access) {
public static Detail from(Post post, AccessModel access, boolean isLiked) {
int length = Math.min(post.getContent().length(), 20);
return Detail.builder()
.id(post.getId())
Expand All @@ -87,6 +88,7 @@ public static Detail from(Post post, AccessModel access) {
.sharedCount(post.getSharedCount())
.canDelete(access.canDelete())
.canModify(access.canModify())
.isLiked(isLiked)
.build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ public PostResponse.Detail getPost(Long memberId, Long postId) {
throw new CustomException(ErrorCode.POST_NOT_FOUND);
}
AccessModel access = getPostAccess(memberId, post.getMember().getId());
return PostResponse.Detail.from(post, access);
boolean isLiked = memberId != 0L && postLikeRepository.findByMemberIdAndPostId(memberId, postId).isPresent();
return PostResponse.Detail.from(post, access, isLiked);
}

/**
Expand Down

0 comments on commit f00e4cc

Please sign in to comment.