Skip to content

Commit 76f9f2b

Browse files
committed
feat: postId를 통해 글 좋아요 여부 조회 API 구현
1 parent 90d0ddb commit 76f9f2b

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

src/main/java/com/back/web7_9_codecrete_be/domain/community/post/controller/PostLikeController.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,14 @@ public RsData<?> getLikeCount(@PathVariable Long postId) {
3535
long count = postLikeService.count(postId);
3636
return RsData.success("게시글 좋아요 수 조회 성공", count);
3737
}
38+
39+
@Operation(summary = "게시글 좋아요 여부 조회", description = "현재 로그인한 사용자가 해당 게시글을 좋아요 했는지 여부를 반환합니다.")
40+
@GetMapping("/me")
41+
public RsData<?> isLikedByMe(@PathVariable Long postId) {
42+
User user = rq.getUser();
43+
boolean liked = postLikeService.isLiked(postId, user.getId());
44+
return RsData.success("게시글 좋아요 여부 조회 성공", liked);
45+
}
46+
47+
3848
}

src/main/java/com/back/web7_9_codecrete_be/domain/community/post/service/PostLikeService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,8 @@ public boolean toggle(Long postId, Long userId) {
3838
public long count(Long postId) {
3939
return postLikeRepository.countByPostId(postId);
4040
}
41+
42+
public boolean isLiked(Long postId, Long userId) {
43+
return postLikeRepository.existsByPostIdAndUserId(postId, userId);
44+
}
4145
}

0 commit comments

Comments
 (0)