Skip to content

Commit

Permalink
[SAMBAD-194] 나와 같은 답변 선택 모임원 조회 시, 본인이 제외되도록 수정 (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
kkjsw17 authored Aug 16, 2024
1 parent 5b43698 commit 487771c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,16 @@ public SelectedAnswerResponse getMostSelectedAnswer(Long userId, Long meetingId,

public SelectedAnswerResponse getSelectedSameAnswer(Long userId, Long meetingId, Long meetingQuestionId) {
meetingMemberValidator.validateUserIsMemberOfMeeting(userId, meetingId);
MeetingMember meetingMember = meetingMemberService.getByUserIdAndMeetingId(userId, meetingId);
MeetingMember meetingMemberOfRequestedUser = meetingMemberService.getByUserIdAndMeetingId(userId, meetingId);

List<MeetingAnswer> meetingAnswers = meetingAnswerRepository.findByMeetingQuestionIdAndMeetingMemberId(
meetingQuestionId, meetingMember.getId());
meetingQuestionId, meetingMemberOfRequestedUser.getId());

List<MeetingMember> members = meetingAnswerRepository.findMeetingMembersSelectWith(
meetingQuestionId, MeetingAnswer.getDistinctAnswerIds(meetingAnswers));
List<Long> answerIds = MeetingAnswer.getDistinctAnswerIds(meetingAnswers);
List<MeetingMember> members = meetingAnswerRepository.findMeetingMembersSelectWith(meetingQuestionId, answerIds)
.stream()
.filter(meetingMemberOfRequestedUser::isNotEqualMemberWith)
.toList();

return SelectedAnswerResponse.from(members, meetingAnswers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ public List<MeetingAnswer> findMostSelectedMeetingAnswer(Long meetingQuestionId)
}

return queryFactory.selectFrom(meetingAnswer)
.where(meetingAnswer.answer.id.eq(mostSelectedAnswerId))
.where(
meetingAnswer.answer.id.eq(mostSelectedAnswerId),
meetingAnswer.meetingQuestion.id.eq(meetingQuestionId)
)
.fetch();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ public record SelectedAnswerResponse(
@Schema(description = "답변 내용", example = "[\"토마토\"]", requiredMode = REQUIRED)
List<String> content,

@Schema(description = "답변 수", example = "3", requiredMode = REQUIRED)
@Schema(description = "해당 모임을 선택한 모임원 수", example = "3", requiredMode = REQUIRED)
int count,

@Schema(description = "선택한 멤버들", requiredMode = REQUIRED)
@Schema(description = "선택한 모임원 목록", requiredMode = REQUIRED)
List<MeetingMemberListResponseDetail> selectedMembers
) {
public static SelectedAnswerResponse from(List<MeetingMember> members, List<MeetingAnswer> meetingAnswers) {
Expand All @@ -27,7 +27,7 @@ public static SelectedAnswerResponse from(List<MeetingMember> members, List<Meet
.map(MeetingAnswer::getAnswerContent)
.distinct()
.toList(),
meetingAnswers.size(),
members.size(),
MeetingMemberListResponse.from(members).contents()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,8 @@ public void validateNextTarget(MeetingMember targetMember) {
throw new InvalidMeetingMemberTargetException();
}
}

public boolean isNotEqualMemberWith(MeetingMember meetingMember) {
return !Objects.equals(this.getId(), meetingMember.getId());
}
}

0 comments on commit 487771c

Please sign in to comment.