diff --git a/src/main/java/itstime/reflog/mypage/controller/MyPageController.java b/src/main/java/itstime/reflog/mypage/controller/MyPageController.java index 0b08327..c8f9fb5 100644 --- a/src/main/java/itstime/reflog/mypage/controller/MyPageController.java +++ b/src/main/java/itstime/reflog/mypage/controller/MyPageController.java @@ -171,6 +171,35 @@ public ResponseEntity>> get return ResponseEntity.ok(CommonApiResponse.onSuccess(responses)); } + @Operation( + summary = "마이페이지 커뮤니티 활동 로그 - 내가 좋아요 한 글 API", + description = "특정 회원에 해당하는 마이페이지 커뮤니티 활동 로그에서 '내가 좋아요 한 글'을 조회합니다.", + responses = { + @ApiResponse( + responseCode = "200", + description = "마이페이지 커뮤니티 활동 로그 - 내가 좋아요 한 글 조회 성공", + content = @Content(schema = @Schema(implementation = CommonApiResponse.class)) + ), + @ApiResponse( + responseCode = "404", + description = "해당 회원 또는 마이페이지 프로필을 찾을 수 없음", + content = @Content(schema = @Schema(implementation = CommonApiResponse.class)) + ), + @ApiResponse( + responseCode = "500", + description = "서버 에러", + content = @Content(schema = @Schema(implementation = CommonApiResponse.class)) + ) + } + ) + @GetMapping("/communitylog/like/posts") + public ResponseEntity>> getMyLikePost( + @UserId String memberId + ) { + List responses = myPageService.getMyLikePost(memberId); + return ResponseEntity.ok(CommonApiResponse.onSuccess(responses)); + } + // @Operation( diff --git a/src/main/java/itstime/reflog/mypage/service/MyPageService.java b/src/main/java/itstime/reflog/mypage/service/MyPageService.java index 677cc36..1070048 100644 --- a/src/main/java/itstime/reflog/mypage/service/MyPageService.java +++ b/src/main/java/itstime/reflog/mypage/service/MyPageService.java @@ -11,6 +11,9 @@ import itstime.reflog.mypage.domain.MyPage; import itstime.reflog.mypage.dto.MyPageDto; import itstime.reflog.mypage.repository.MyPageRepository; +import itstime.reflog.postlike.domain.PostLike; +import itstime.reflog.postlike.domain.enums.PostType; +import itstime.reflog.postlike.repository.PostLikeRepository; import itstime.reflog.postlike.service.PostLikeService; import itstime.reflog.retrospect.domain.Retrospect; import itstime.reflog.retrospect.repository.RetrospectRepository; @@ -35,6 +38,7 @@ public class MyPageService { private final CommunityRepository communityRepository; private final RetrospectRepository retrospectRepository; private final CommentRepository commentRepository; + private final PostLikeRepository postLikeRepository; private final PostLikeService postLikeService; @Transactional @@ -136,4 +140,45 @@ public List getMyPost(String memberId) { responses.addAll(retrospectResponses); return responses; } + + @Transactional + public List getMyLikePost(String memberId) { + // 1. 멤버 조회 + Member member = memberRepository.findByUuid(UUID.fromString(memberId)) + .orElseThrow(() -> new GeneralException(ErrorStatus._MEMBER_NOT_FOUND)); + + // 2. 내가 좋아요 한 커뮤니티 글 전체조회 + List postLikeList = postLikeRepository.findAllByMemberAndPostType(member, PostType.COMMUNITY); + + // 3. 내가 좋아요 한 커뮤니티 글 정리 + List responses = postLikeList.stream() + .map(postLike -> { + + // 좋아요 총 개수 + int totalLike = postLikeService.getSumCommunityPostLike(postLike.getCommunity()); + // 댓글 총 개수 + long commentCount = commentRepository.countByCommunity(postLike.getCommunity()); + + return MyPageDto.MyPagePostResponse.fromCommunity(postLike.getCommunity(), totalLike, commentCount); + }) + .collect(Collectors.toList()); + + // 4. 내가 좋아요 한 회고일지 글 전체조회 + List postLikeList1 = postLikeRepository.findAllByMemberAndPostType(member, PostType.RETROSPECT); + + // 5. 내가 좋아요 한 회고일지 글 정리 + List retrospectResponses = postLikeList1.stream() + .map(postLike -> { + + // 좋아요 총 개수 + int totalLike = postLikeService.getSumRetrospectPostLike(postLike.getRetrospect()); + // 댓글 총 개수 + long commentCount = commentRepository.countByRetrospect(postLike.getRetrospect()); + + return MyPageDto.MyPagePostResponse.fromRetrospect(postLike.getRetrospect(), totalLike, commentCount); + }).toList(); + + responses.addAll(retrospectResponses); + return responses; + } } diff --git a/src/main/java/itstime/reflog/postlike/repository/PostLikeRepository.java b/src/main/java/itstime/reflog/postlike/repository/PostLikeRepository.java index 5ec6017..f37a73c 100644 --- a/src/main/java/itstime/reflog/postlike/repository/PostLikeRepository.java +++ b/src/main/java/itstime/reflog/postlike/repository/PostLikeRepository.java @@ -1,5 +1,6 @@ package itstime.reflog.postlike.repository; +import itstime.reflog.postlike.domain.enums.PostType; import org.springframework.data.repository.query.Param; import itstime.reflog.community.domain.Community; import itstime.reflog.member.domain.Member; @@ -8,6 +9,7 @@ import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Query; +import java.util.List; import java.util.Optional; public interface PostLikeRepository extends JpaRepository { @@ -23,4 +25,7 @@ public interface PostLikeRepository extends JpaRepository { //DB에서 retrospect 좋아요 합 계산 @Query("SELECT COUNT(pl) FROM PostLike pl WHERE pl.retrospect = :retrospect") int countByRetrospect(@Param("retrospect") Retrospect retrospect); + + // 내가 좋아요를 누른 모든 커뮤니티 or 회고일지 글 + List findAllByMemberAndPostType(Member member, PostType postType); }