Skip to content

Commit

Permalink
feat : 마이페이지 좋아요 한 글 API #46
Browse files Browse the repository at this point in the history
  • Loading branch information
dhun0103 committed Jan 6, 2025
1 parent bdb95ed commit 68ba2e8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,35 @@ public ResponseEntity<CommonApiResponse<List<MyPageDto.MyPagePostResponse>>> 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<CommonApiResponse<List<MyPageDto.MyPagePostResponse>>> getMyLikePost(
@UserId String memberId
) {
List<MyPageDto.MyPagePostResponse> responses = myPageService.getMyLikePost(memberId);
return ResponseEntity.ok(CommonApiResponse.onSuccess(responses));
}



// @Operation(
Expand Down
45 changes: 45 additions & 0 deletions src/main/java/itstime/reflog/mypage/service/MyPageService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -136,4 +140,45 @@ public List<MyPageDto.MyPagePostResponse> getMyPost(String memberId) {
responses.addAll(retrospectResponses);
return responses;
}

@Transactional
public List<MyPageDto.MyPagePostResponse> getMyLikePost(String memberId) {
// 1. 멤버 조회
Member member = memberRepository.findByUuid(UUID.fromString(memberId))
.orElseThrow(() -> new GeneralException(ErrorStatus._MEMBER_NOT_FOUND));

// 2. 내가 좋아요 한 커뮤니티 글 전체조회
List<PostLike> postLikeList = postLikeRepository.findAllByMemberAndPostType(member, PostType.COMMUNITY);

// 3. 내가 좋아요 한 커뮤니티 글 정리
List<MyPageDto.MyPagePostResponse> 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<PostLike> postLikeList1 = postLikeRepository.findAllByMemberAndPostType(member, PostType.RETROSPECT);

// 5. 내가 좋아요 한 회고일지 글 정리
List<MyPageDto.MyPagePostResponse> 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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<PostLike, Long> {
Expand All @@ -23,4 +25,7 @@ public interface PostLikeRepository extends JpaRepository<PostLike, Long> {
//DB에서 retrospect 좋아요 합 계산
@Query("SELECT COUNT(pl) FROM PostLike pl WHERE pl.retrospect = :retrospect")
int countByRetrospect(@Param("retrospect") Retrospect retrospect);

// 내가 좋아요를 누른 모든 커뮤니티 or 회고일지 글
List<PostLike> findAllByMemberAndPostType(Member member, PostType postType);
}

0 comments on commit 68ba2e8

Please sign in to comment.