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/139] 매너평가 조회 API 구현 #140

Merged
merged 4 commits into from
Aug 10, 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
@@ -1,4 +1,4 @@
package com.gamegoo.domain;
package com.gamegoo.domain.matching;

import static com.querydsl.core.types.PathMetadataFactory.*;

Expand All @@ -16,7 +16,7 @@
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QMatchingRecord extends EntityPathBase<MatchingRecord> {

private static final long serialVersionUID = 75682738L;
private static final long serialVersionUID = 1978268795L;

private static final PathInits INITS = PathInits.DIRECT2;

Expand All @@ -35,19 +35,19 @@ public class QMatchingRecord extends EntityPathBase<MatchingRecord> {

public final NumberPath<Integer> mannerLevel = createNumber("mannerLevel", Integer.class);

public final StringPath matchingType = createString("matchingType");
public final EnumPath<MatchingType> matchingType = createEnum("matchingType", MatchingType.class);

public final com.gamegoo.domain.Member.QMember member;
public final com.gamegoo.domain.member.QMember member;

public final BooleanPath mike = createBoolean("mike");

public final StringPath rank = createString("rank");

public final StringPath status = createString("status");
public final EnumPath<MatchingStatus> status = createEnum("status", MatchingStatus.class);

public final NumberPath<Integer> subPosition = createNumber("subPosition", Integer.class);

public final EnumPath<com.gamegoo.domain.Member.Tier> tier = createEnum("tier", com.gamegoo.domain.Member.Tier.class);
public final EnumPath<com.gamegoo.domain.member.Tier> tier = createEnum("tier", com.gamegoo.domain.member.Tier.class);

//inherited
public final DateTimePath<java.time.LocalDateTime> updatedAt = _super.updatedAt;
Expand All @@ -74,7 +74,7 @@ public QMatchingRecord(PathMetadata metadata, PathInits inits) {

public QMatchingRecord(Class<? extends MatchingRecord> type, PathMetadata metadata, PathInits inits) {
super(type, metadata, inits);
this.member = inits.isInitialized("member") ? new com.gamegoo.domain.Member.QMember(forProperty("member")) : null;
this.member = inits.isInitialized("member") ? new com.gamegoo.domain.member.QMember(forProperty("member")) : null;
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,14 @@ public enum ErrorStatus implements BaseErrorCode {

// 매너평가 관련 에러
MANNER_TARGET_MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "MANNER401", "매너 평가 대상 회원을 찾을 수 없습니다."),
BAD_MANNER_TARGET_MEMBER_NOT_FOUND(HttpStatus.NOT_FOUND, "MANNER401", "비매너 평가 대상 회원을 찾을 수 없습니다."),
MANNER_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "MANNER401", "매너평가 작성자만 수정 가능합니다."),
MANNER_KEYWORD_TYPE_INVALID(HttpStatus.BAD_REQUEST, "MANNER401", "매너 키워드 유형은 1~6만 가능합니다."),
BAD_MANNER_KEYWORD_TYPE_INVALID(HttpStatus.BAD_REQUEST, "MANNER401",
"비매너 키워드 유형은 7~12만 가능합니다."),
MANNER_KEYWORD_NOT_FOUND(HttpStatus.NOT_FOUND, "MANNER404", "해당 매너 키워드를 찾을 수 없습니다."),
MANNER_NOT_FOUND(HttpStatus.NOT_FOUND, "MANNER404", "해당 매너평가를 찾을 수 없습니다."),
BAD_MANNER_NOT_FOUND(HttpStatus.NOT_FOUND, "MANNER404", "해당 비매너평가를 찾을 수 없습니다."),
MANNER_CONFLICT(HttpStatus.CONFLICT, "MANNER409", "매너 평가는 최초 1회만 가능합니다."),
BAD_MANNER_CONFLICT(HttpStatus.CONFLICT, "MANNER409", "비매너 평가는 최초 1회만 가능합니다."),

Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/gamegoo/controller/mannner/MannerController.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,28 @@ public ApiResponse<MannerResponse.mannerUpdateResponseDTO> mannerUpdate(
return ApiResponse.onSuccess(result);

}

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

Long memberId = JWTUtil.getCurrentUserId();

MannerResponse.mannerKeywordResponseDTO result = mannerService.getMannerKeyword(memberId, targetMemberId);

return ApiResponse.onSuccess(result);
}

@GetMapping("bad/{memberId}")
@Operation(summary = "비매너 평가 조회 API", description = "회원이 실시한 비매너 평가를 조회하는 API 입니다.")
@Parameter(name = "memberId", description = "회원이 실시한 비매너평가 대상의 id 입니다.")
public ApiResponse<MannerResponse.badMannerKeywordResponseDTO> getBadMannerKeyword(@PathVariable(name = "memberId") Long targetMemberId){

Long memberId = JWTUtil.getCurrentUserId();

MannerResponse.badMannerKeywordResponseDTO result = mannerService.getBadMannerKeyword(memberId, targetMemberId);

return ApiResponse.onSuccess(result);
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/gamegoo/dto/manner/MannerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,22 @@ public static class mannerUpdateResponseDTO{
Long mannerId;
List<Long> mannerRatingKeywordList;
}

@Getter
@Builder
@Setter
@NoArgsConstructor
@AllArgsConstructor
public static class mannerKeywordResponseDTO{
List<Long> mannerRatingKeywordList;
}

@Getter
@Builder
@Setter
Comment on lines +38 to +39
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builder나 Setter 둘 중 하나만 사용해도 좋을 것 같아요! Builder만 사용하는거 어떠세요!?

@NoArgsConstructor
@AllArgsConstructor
public static class badMannerKeywordResponseDTO{
List<Long> mannerRatingKeywordList;
}
}
66 changes: 66 additions & 0 deletions src/main/java/com/gamegoo/service/manner/MannerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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();
}
}
Loading