diff --git a/src/main/java/com/gdsc_knu/official_homepage/dto/post/PostResponse.java b/src/main/java/com/gdsc_knu/official_homepage/dto/post/PostResponse.java index edebd10a..c84f2cba 100644 --- a/src/main/java/com/gdsc_knu/official_homepage/dto/post/PostResponse.java +++ b/src/main/java/com/gdsc_knu/official_homepage/dto/post/PostResponse.java @@ -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()) @@ -87,6 +88,7 @@ public static Detail from(Post post, AccessModel access) { .sharedCount(post.getSharedCount()) .canDelete(access.canDelete()) .canModify(access.canModify()) + .isLiked(isLiked) .build(); } diff --git a/src/main/java/com/gdsc_knu/official_homepage/service/post/PostServiceImpl.java b/src/main/java/com/gdsc_knu/official_homepage/service/post/PostServiceImpl.java index 64b13240..b89d7012 100644 --- a/src/main/java/com/gdsc_knu/official_homepage/service/post/PostServiceImpl.java +++ b/src/main/java/com/gdsc_knu/official_homepage/service/post/PostServiceImpl.java @@ -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); } /**