diff --git a/src/main/java/cotato/growingpain/comment/controller/CommentLikeController.java b/src/main/java/cotato/growingpain/comment/controller/CommentLikeController.java index 365128e..3ada3ca 100644 --- a/src/main/java/cotato/growingpain/comment/controller/CommentLikeController.java +++ b/src/main/java/cotato/growingpain/comment/controller/CommentLikeController.java @@ -54,7 +54,6 @@ public Response deleteLike(@PathVariable Long commentId, return Response.createSuccessWithNoData("댓글 좋아요 취소 완료"); } - @Operation(summary = "좋아요 누른 댓글 목록 조회", description = "사용자가 좋아요를 누른 댓글의 목록을 조회하기 위한 메소드") @ApiResponse(content = @Content(schema = @Schema(implementation = Response.class))) @GetMapping("/{memberId}/list") diff --git a/src/main/java/cotato/growingpain/comment/service/CommentLikeService.java b/src/main/java/cotato/growingpain/comment/service/CommentLikeService.java index 259916c..0c3d67b 100644 --- a/src/main/java/cotato/growingpain/comment/service/CommentLikeService.java +++ b/src/main/java/cotato/growingpain/comment/service/CommentLikeService.java @@ -9,7 +9,6 @@ import cotato.growingpain.member.domain.entity.Member; import cotato.growingpain.member.repository.MemberRepository; import java.util.List; -import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -59,10 +58,9 @@ public List getLikedComments(Long memberId) { return commentLikes.stream() .map(CommentLike::getComment) - .collect(Collectors.toList()); + .toList(); } - private Comment findCommentId(Long commentId) { return commentRepository.findById(commentId) .orElseThrow(() -> new AppException(ErrorCode.COMMENT_NOT_FOUND)); diff --git a/src/main/java/cotato/growingpain/replycomment/controller/ReplyCommentLikeController.java b/src/main/java/cotato/growingpain/replycomment/controller/ReplyCommentLikeController.java index 20220af..88f518f 100644 --- a/src/main/java/cotato/growingpain/replycomment/controller/ReplyCommentLikeController.java +++ b/src/main/java/cotato/growingpain/replycomment/controller/ReplyCommentLikeController.java @@ -1,17 +1,21 @@ package cotato.growingpain.replycomment.controller; import cotato.growingpain.common.Response; +import cotato.growingpain.replycomment.domain.entity.ReplyComment; +import cotato.growingpain.replycomment.dto.response.ReplyCommentListResponse; import cotato.growingpain.replycomment.service.ReplyCommentLikeService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.tags.Tag; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.http.HttpStatus; import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.DeleteMapping; +import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @@ -21,7 +25,7 @@ @Tag(name = "답글 좋아요", description = "답글 좋아요 관련된 api") @RestController @RequiredArgsConstructor -@RequestMapping("/api/reply-comment/likes/{replyCommentId}") +@RequestMapping("/api/reply-comment/likes") @Slf4j public class ReplyCommentLikeController { @@ -29,7 +33,7 @@ public class ReplyCommentLikeController { @Operation(summary = "답글 좋아요 등록", description = "답글 좋아요 등록을 위한 메소드") @ApiResponse(content = @Content(schema = @Schema(implementation = Response.class))) - @PostMapping("") + @PostMapping("/{replyCommentId}") @ResponseStatus(HttpStatus.CREATED) public Response registerLike(@PathVariable Long replyCommentId, @AuthenticationPrincipal Long memberId) { @@ -41,7 +45,7 @@ public Response registerLike(@PathVariable Long replyCommentId, @Operation(summary = "답글 좋아요 취소", description = "답글 좋아요 취소를 위한 메소드") @ApiResponse(content = @Content(schema = @Schema(implementation = Response.class))) - @DeleteMapping("") + @DeleteMapping("/{replyCommentId}") @ResponseStatus(HttpStatus.OK) public Response deleteLike(@PathVariable Long replyCommentId, @AuthenticationPrincipal Long memberId) { @@ -49,4 +53,15 @@ public Response deleteLike(@PathVariable Long replyCommentId, replyCommentLikeService.deleteLike(replyCommentId, memberId); return Response.createSuccessWithNoData("답글 좋아요 취소 완료"); } + + @Operation(summary = "좋아요 누른 답글 목록 조회", description = "사용자가 좋아요를 누른 답글의 목록을 조회하기 위한 메소드") + @ApiResponse(content = @Content(schema = @Schema(implementation = Response.class))) + @GetMapping("/{memberId}/list") + @ResponseStatus(HttpStatus.OK) + public Response getLikeReplyComments(@AuthenticationPrincipal Long memberId) { + log.info("사용자가 좋아요를 누른 답글 목록 요청: memberId {}", memberId); + List likedReplyComments = replyCommentLikeService.getLikedReplyComments(memberId); + ReplyCommentListResponse replyCommentListResponse = ReplyCommentListResponse.from(likedReplyComments); + return Response.createSuccess("좋아요를 누른 댓글 목록 조회 완료", replyCommentListResponse); + } } diff --git a/src/main/java/cotato/growingpain/replycomment/dto/response/ReplyCommentListResponse.java b/src/main/java/cotato/growingpain/replycomment/dto/response/ReplyCommentListResponse.java index 72017ed..be70d47 100644 --- a/src/main/java/cotato/growingpain/replycomment/dto/response/ReplyCommentListResponse.java +++ b/src/main/java/cotato/growingpain/replycomment/dto/response/ReplyCommentListResponse.java @@ -1,8 +1,15 @@ package cotato.growingpain.replycomment.dto.response; +import cotato.growingpain.replycomment.domain.entity.ReplyComment; import java.util.List; public record ReplyCommentListResponse( List replyCommentList ) { + public static ReplyCommentListResponse from(List replyComments) { + List replyCommentResponses = replyComments.stream() + .map(ReplyCommentResponse::from) + .toList(); + return new ReplyCommentListResponse(replyCommentResponses); + } } \ No newline at end of file diff --git a/src/main/java/cotato/growingpain/replycomment/repository/ReplyCommentLikeRepository.java b/src/main/java/cotato/growingpain/replycomment/repository/ReplyCommentLikeRepository.java index dc795f6..f5f0a0e 100644 --- a/src/main/java/cotato/growingpain/replycomment/repository/ReplyCommentLikeRepository.java +++ b/src/main/java/cotato/growingpain/replycomment/repository/ReplyCommentLikeRepository.java @@ -3,6 +3,7 @@ import cotato.growingpain.member.domain.entity.Member; import cotato.growingpain.replycomment.domain.entity.ReplyComment; import cotato.growingpain.replycomment.domain.entity.ReplyCommentLike; +import java.util.List; import java.util.Optional; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; @@ -17,4 +18,5 @@ public interface ReplyCommentLikeRepository extends JpaRepository findAllByMemberAndReplyComment(Member member, ReplyComment replyComment); + List findAllByMemberId(Long memberId); } \ No newline at end of file diff --git a/src/main/java/cotato/growingpain/replycomment/service/ReplyCommentLikeService.java b/src/main/java/cotato/growingpain/replycomment/service/ReplyCommentLikeService.java index ad5ab75..672f518 100644 --- a/src/main/java/cotato/growingpain/replycomment/service/ReplyCommentLikeService.java +++ b/src/main/java/cotato/growingpain/replycomment/service/ReplyCommentLikeService.java @@ -8,6 +8,7 @@ import cotato.growingpain.replycomment.domain.entity.ReplyCommentLike; import cotato.growingpain.replycomment.repository.ReplyCommentLikeRepository; import cotato.growingpain.replycomment.repository.ReplyCommentRepository; +import java.util.List; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -41,11 +42,12 @@ public void registerLike(Long replyCommentId, Long memberId) { } @Transactional - public void deleteLike(Long replyCommentId, Long memberId) { + public void deleteLike(Long replyCommentId, Long memberId) { ReplyComment replyComment = findReplyCommentById(replyCommentId); Member member = findMemberById(memberId); - ReplyCommentLike replyCommentLike = replyCommentLikeRepository.findAllByMemberAndReplyComment(member, replyComment) + ReplyCommentLike replyCommentLike = replyCommentLikeRepository.findAllByMemberAndReplyComment(member, + replyComment) .orElseThrow(() -> new AppException(ErrorCode.REPLY_COMMENT_LIKE_NOT_FOUND)); replyCommentLike.decreaseReplyCommentLikeCount(member, replyComment); @@ -60,4 +62,13 @@ private ReplyComment findReplyCommentById(Long replyCommentId) { private Member findMemberById(Long memberId) { return memberRepository.getReferenceById(memberId); } + + @Transactional + public List getLikedReplyComments(Long memberId) { + List replyCommentLikes = replyCommentLikeRepository.findAllByMemberId(memberId); + + return replyCommentLikes.stream() + .map(ReplyCommentLike::getReplyComment) + .toList(); + } } diff --git a/src/main/java/cotato/growingpain/replycomment/service/ReplyCommentService.java b/src/main/java/cotato/growingpain/replycomment/service/ReplyCommentService.java index 279c5eb..1c97d15 100644 --- a/src/main/java/cotato/growingpain/replycomment/service/ReplyCommentService.java +++ b/src/main/java/cotato/growingpain/replycomment/service/ReplyCommentService.java @@ -66,4 +66,4 @@ public void deleteReplyComment(Long replyCommentId, Long memberId) { replyComment.deleteReplyComment(); replyCommentRepository.save(replyComment); } -} \ No newline at end of file +}