Skip to content

Commit

Permalink
[NO_JIRA] reviews teamId null 일 때 오류 fix (#108)
Browse files Browse the repository at this point in the history
* refactor : 변환 메서드 이너 클래스 내부로 이동

* fix : reviews API teamId == null 오류 fix
  • Loading branch information
wjdwnsdnjs13 authored Aug 3, 2024
1 parent 20445d8 commit 9cf7d68
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<Long> keywordIds =
review.getKeywords().stream()
Expand Down

0 comments on commit 9cf7d68

Please sign in to comment.