-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat/139] 매너평가 조회 API 구현 #140
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import com.gamegoo.domain.manner.MannerRating; | ||
import com.gamegoo.domain.manner.MannerRatingKeyword; | ||
import com.gamegoo.dto.manner.MannerRequest; | ||
import com.gamegoo.dto.manner.MannerResponse; | ||
import com.gamegoo.repository.manner.MannerKeywordRepository; | ||
import com.gamegoo.repository.manner.MannerRatingKeywordRepository; | ||
import com.gamegoo.repository.manner.MannerRatingRepository; | ||
|
@@ -255,4 +256,69 @@ public MannerRating update(MannerRequest.mannerUpdateDTO request, Long memberId, | |
} | ||
|
||
} | ||
|
||
// 매너평가 조회 | ||
@Transactional(readOnly = true) | ||
public MannerResponse.mannerKeywordResponseDTO getMannerKeyword(Long memberId, Long targetMemberId){ | ||
|
||
Member member = memberRepository.findById(memberId).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); | ||
|
||
// 매너평가를 받은 회원 존재 여부 검증. | ||
Member targetMember = memberRepository.findById(targetMemberId).orElseThrow(() -> new MemberHandler(ErrorStatus.MANNER_TARGET_MEMBER_NOT_FOUND)); | ||
|
||
// 매너평가를 받은 회원 탈퇴 여부 검증. | ||
if (targetMember.getBlind()) { | ||
throw new MemberHandler(ErrorStatus.USER_DEACTIVATED); | ||
} | ||
|
||
// 매너평가 ID 조회 | ||
List<MannerRating> mannerRatings = mannerRatingRepository.findByFromMemberIdAndToMemberId(member.getId(), targetMember.getId()); | ||
List<MannerRating> positiveMannerRatings = mannerRatings.stream() | ||
.filter(MannerRating::getIsPositive) | ||
.collect(Collectors.toList()); | ||
Comment on lines
+275
to
+278
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기서 굳이 전체 mannerRating을 조회한 다음에 stream filter로 positive인 애를 거르지 말고, repository에서 mannerRating을 조회할 때 findByFromMemberIdAndToMemberAndIsPositive ? 이런 식으로 boolean 값까지 입력 받아서 조회하는 방식은 어떤가요?! |
||
|
||
if (positiveMannerRatings.isEmpty()) { | ||
throw new MannerHandler(ErrorStatus.MANNER_NOT_FOUND); | ||
} | ||
|
||
MannerRating positiveMannerRating = positiveMannerRatings.get(0); | ||
|
||
List<Long> mannerKeywordIds = positiveMannerRating.getMannerRatingKeywordList().stream() | ||
.map(mannerRatingKeyword -> mannerRatingKeyword.getMannerKeyword().getId()) | ||
.collect(Collectors.toList()); | ||
|
||
return MannerResponse.mannerKeywordResponseDTO.builder() | ||
.mannerRatingKeywordList(mannerKeywordIds) | ||
.build(); | ||
} | ||
|
||
// 비매너평가 조회 | ||
@Transactional(readOnly = true) | ||
public MannerResponse.badMannerKeywordResponseDTO getBadMannerKeyword(Long memberId, Long targetMemberId){ | ||
|
||
Member member = memberRepository.findById(memberId).orElseThrow(() -> new MemberHandler(ErrorStatus.MEMBER_NOT_FOUND)); | ||
|
||
// 비매너평가를 받은 회원 존재 여부 검증. | ||
Member targetMember = memberRepository.findById(targetMemberId).orElseThrow(() -> new MemberHandler(ErrorStatus.BAD_MANNER_TARGET_MEMBER_NOT_FOUND)); | ||
|
||
// 비매너평가 ID 조회 | ||
List<MannerRating> mannerRatings = mannerRatingRepository.findByFromMemberIdAndToMemberId(member.getId(), targetMember.getId()); | ||
List<MannerRating> negativeMannerRatings = mannerRatings.stream() | ||
.filter(mannerRating -> !mannerRating.getIsPositive()) | ||
.collect(Collectors.toList()); | ||
|
||
if (negativeMannerRatings.isEmpty()) { | ||
throw new MannerHandler(ErrorStatus.BAD_MANNER_NOT_FOUND); | ||
} | ||
|
||
MannerRating negativeMannerRating = negativeMannerRatings.get(0); | ||
|
||
List<Long> badMannerKeywordIds = negativeMannerRating.getMannerRatingKeywordList().stream() | ||
.map(mannerRatingKeyword -> mannerRatingKeyword.getMannerKeyword().getId()) | ||
.collect(Collectors.toList()); | ||
|
||
return MannerResponse.badMannerKeywordResponseDTO.builder() | ||
.mannerRatingKeywordList(badMannerKeywordIds) | ||
.build(); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Builder나 Setter 둘 중 하나만 사용해도 좋을 것 같아요! Builder만 사용하는거 어떠세요!?