diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/review/ReadReviewUsecase.java b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/review/ReadReviewUsecase.java index 61f87455..f95a84d4 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/port/in/review/ReadReviewUsecase.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/port/in/review/ReadReviewUsecase.java @@ -2,6 +2,7 @@ import java.util.List; +import org.depromeet.spot.domain.member.Member; import org.depromeet.spot.domain.review.Review; import org.depromeet.spot.domain.review.ReviewYearMonth; import org.depromeet.spot.domain.review.image.TopReviewImage; @@ -66,7 +67,34 @@ record MemberInfoOnMyReviewResult( String nickname, Long reviewCount, Long teamId, - String teamName) {} + String teamName) { + public static MemberInfoOnMyReviewResult of(Member member, long totalReviewCount) { + return MemberInfoOnMyReviewResult.builder() + .userId(member.getId()) + .profileImageUrl(member.getProfileImage()) + .level(member.getLevel().getValue()) + .levelTitle(member.getLevel().getTitle()) + .nickname(member.getNickname()) + .reviewCount(totalReviewCount) + .teamId(null) + .teamName(null) + .build(); + } + + public static MemberInfoOnMyReviewResult of( + Member member, long totalReviewCount, String teamName) { + return MemberInfoOnMyReviewResult.builder() + .userId(member.getId()) + .profileImageUrl(member.getProfileImage()) + .level(member.getLevel().getValue()) + .levelTitle(member.getLevel().getTitle()) + .nickname(member.getNickname()) + .reviewCount(totalReviewCount) + .teamId(member.getTeamId()) + .teamName(teamName) + .build(); + } + } @Builder record MyRecentReviewResult(Review review, Long reviewCount) {} diff --git a/usecase/src/main/java/org/depromeet/spot/usecase/service/review/ReadReviewService.java b/usecase/src/main/java/org/depromeet/spot/usecase/service/review/ReadReviewService.java index 169a02d9..fe0ac441 100644 --- a/usecase/src/main/java/org/depromeet/spot/usecase/service/review/ReadReviewService.java +++ b/usecase/src/main/java/org/depromeet/spot/usecase/service/review/ReadReviewService.java @@ -93,11 +93,17 @@ public MyReviewListResult findMyReviewsByUserId( Member member = memberRepository.findById(userId); - BaseballTeam baseballTeam = baseballTeamRepository.findById(member.getTeamId()); + MemberInfoOnMyReviewResult memberInfo; + if (member.getTeamId() == null) { + memberInfo = MemberInfoOnMyReviewResult.of(member, reviewPage.getTotalElements()); - MemberInfoOnMyReviewResult memberInfo = - createMemberInfoFromMember( - member, reviewPage.getTotalElements(), baseballTeam.getName()); + } else { + BaseballTeam baseballTeam = baseballTeamRepository.findById(member.getTeamId()); + + memberInfo = + MemberInfoOnMyReviewResult.of( + member, reviewPage.getTotalElements(), baseballTeam.getName()); + } return MyReviewListResult.builder() .memberInfoOnMyReviewResult(memberInfo) @@ -147,20 +153,6 @@ public MyRecentReviewResult findLastReviewByMemberId(Long memberId) { .build(); } - private MemberInfoOnMyReviewResult createMemberInfoFromMember( - Member member, long totalReviewCount, String teamName) { - return MemberInfoOnMyReviewResult.builder() - .userId(member.getId()) - .profileImageUrl(member.getProfileImage()) - .level(member.getLevel().getValue()) - .levelTitle(member.getLevel().getTitle()) - .nickname(member.getNickname()) - .reviewCount(totalReviewCount) - .teamId(member.getTeamId()) - .teamName(teamName) - .build(); - } - private Review mapKeywordsToSingleReview(Review review) { List keywordIds = review.getKeywords().stream()