Skip to content

Commit

Permalink
Merge pull request #157 from Gamegoo-repo/feat/155
Browse files Browse the repository at this point in the history
[Feat/155] ๋งค๋„ˆ ํ‰๊ฐ€ ์กฐํšŒ ์ถ”๊ฐ€ ๊ตฌํ˜„
  • Loading branch information
hzee97 authored Aug 11, 2024
2 parents c96a1df + 10df875 commit de2d7a3
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 24 deletions.
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

0 comments on commit de2d7a3

Please sign in to comment.