Skip to content
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/155] 매너 평가 조회 추가 구현 #157

Merged
merged 3 commits into from
Aug 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public ApiResponse<MannerResponse.mannerUpdateResponseDTO> mannerUpdate(

}

@GetMapping("good/{memberId}")
@GetMapping("/good/{memberId}")
@Operation(summary = "매너 평가 조회 API", description = "회원이 실시한 매너 평가를 조회하는 API 입니다.")
@Parameter(name = "memberId", description = "회원이 실시한 매너평가 대상의 id 입니다.")
public ApiResponse<MannerResponse.mannerKeywordResponseDTO> getMannerKeyword(@PathVariable(name = "memberId") Long targetMemberId){
Expand All @@ -106,7 +106,7 @@ public ApiResponse<MannerResponse.mannerKeywordResponseDTO> getMannerKeyword(@Pa
return ApiResponse.onSuccess(result);
}

@GetMapping("bad/{memberId}")
@GetMapping("/bad/{memberId}")
@Operation(summary = "비매너 평가 조회 API", description = "회원이 실시한 비매너 평가를 조회하는 API 입니다.")
@Parameter(name = "memberId", description = "회원이 실시한 비매너평가 대상의 id 입니다.")
public ApiResponse<MannerResponse.badMannerKeywordResponseDTO> getBadMannerKeyword(@PathVariable(name = "memberId") Long targetMemberId){
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/gamegoo/dto/manner/MannerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public static class mannerUpdateResponseDTO{
@NoArgsConstructor
@AllArgsConstructor
public static class mannerKeywordResponseDTO{
Boolean isPositive;
Boolean isExist;
List<Long> mannerRatingKeywordList;
}

Expand All @@ -38,6 +40,8 @@ public static class mannerKeywordResponseDTO{
@NoArgsConstructor
@AllArgsConstructor
public static class badMannerKeywordResponseDTO{
Boolean isPositive;
Boolean isExist;
List<Long> mannerRatingKeywordList;
}

Expand All @@ -49,14 +53,13 @@ public static class myMannerResponseDTO{
Integer mannerLevel;
List<mannerKeywordDTO> mannerKeywords;
}

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class mannerKeywordDTO{
Boolean isPositive;
Integer mannerKeywordId;
Integer count;
Boolean isPositive;
Integer mannerKeywordId;
Integer count;
}
}
69 changes: 51 additions & 18 deletions src/main/java/com/gamegoo/service/manner/MannerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,8 @@ public MannerResponse.mannerKeywordResponseDTO getMannerKeyword(Long memberId, L
// 매너평가를 받은 회원 존재 여부 검증.
Member targetMember = memberRepository.findById(targetMemberId).orElseThrow(() -> new MemberHandler(ErrorStatus.MANNER_TARGET_MEMBER_NOT_FOUND));

Boolean isExist;

// 매너평가를 받은 회원 탈퇴 여부 검증.
if (targetMember.getBlind()) {
throw new MemberHandler(ErrorStatus.USER_DEACTIVATED);
Expand All @@ -379,18 +381,33 @@ public MannerResponse.mannerKeywordResponseDTO getMannerKeyword(Long memberId, L
.collect(Collectors.toList());

if (positiveMannerRatings.isEmpty()) {
throw new MannerHandler(ErrorStatus.MANNER_NOT_FOUND);
}

MannerRating positiveMannerRating = positiveMannerRatings.get(0);
isExist = false;

List<Long> mannerKeywordIds = positiveMannerRating.getMannerRatingKeywordList().stream()
.map(mannerRatingKeyword -> mannerRatingKeyword.getMannerKeyword().getId())
.collect(Collectors.toList());
List<Long> mannerKeywordIds = Collections.emptyList();

return MannerResponse.mannerKeywordResponseDTO.builder()
.mannerRatingKeywordList(mannerKeywordIds)
.build();
return MannerResponse.mannerKeywordResponseDTO.builder()
.isPositive(true)
.isExist(isExist)
.mannerRatingKeywordList(mannerKeywordIds)
.build();

} else {

isExist = true;

MannerRating positiveMannerRating = positiveMannerRatings.get(0);

List<Long> mannerKeywordIds = positiveMannerRating.getMannerRatingKeywordList().stream()
.map(mannerRatingKeyword -> mannerRatingKeyword.getMannerKeyword().getId())
.collect(Collectors.toList());

return MannerResponse.mannerKeywordResponseDTO.builder()
.isPositive(true)
.isExist(isExist)
.mannerRatingKeywordList(mannerKeywordIds)
.build();
}
}

// 비매너평가 조회
Expand All @@ -402,25 +419,41 @@ public MannerResponse.badMannerKeywordResponseDTO getBadMannerKeyword(Long membe
// 비매너평가를 받은 회원 존재 여부 검증.
Member targetMember = memberRepository.findById(targetMemberId).orElseThrow(() -> new MemberHandler(ErrorStatus.BAD_MANNER_TARGET_MEMBER_NOT_FOUND));

Boolean isExist;

// 비매너평가 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);
isExist = false;

List<Long> badMannerKeywordIds = negativeMannerRating.getMannerRatingKeywordList().stream()
.map(mannerRatingKeyword -> mannerRatingKeyword.getMannerKeyword().getId())
.collect(Collectors.toList());
List<Long> badMannerKeywordIds = Collections.emptyList();

return MannerResponse.badMannerKeywordResponseDTO.builder()
.mannerRatingKeywordList(badMannerKeywordIds)
.build();
return MannerResponse.badMannerKeywordResponseDTO.builder()
.isPositive(false)
.isExist(isExist)
.mannerRatingKeywordList(badMannerKeywordIds)
.build();
} else {

isExist = true;

MannerRating negativeMannerRating = negativeMannerRatings.get(0);

List<Long> badMannerKeywordIds = negativeMannerRating.getMannerRatingKeywordList().stream()
.map(mannerRatingKeyword -> mannerRatingKeyword.getMannerKeyword().getId())
.collect(Collectors.toList());

return MannerResponse.badMannerKeywordResponseDTO.builder()
.isPositive(false)
.isExist(isExist)
.mannerRatingKeywordList(badMannerKeywordIds)
.build();
}
}

// 내가 받은 매너 평가 조회
Expand Down
Loading