woowacourse-teams / 2024-corea

코드리뷰 매칭 플랫폼, CoReA
https://code-review-area.com/
13 stars 7 forks source link

[BE] PR 제출하지 않은 사람도 방에 참여중인 사람 목록에 포함되는 현상 제거(#583) #585

Closed github-actions[bot] closed 1 week ago

github-actions[bot] commented 1 week ago

📌 관련 이슈

✨ PR 세부 내용

현재 정책 상 참여자 중 PR을 제출하지 않은 사람은 매칭에서 제외되고 있습니다. = MatchResult가 존재하지 않습니다.

그런데 findParticipants로 같은 방에 참여 중인 다른 사람 리스트를 불러올 때, 해당 방에 참여한 기록(= participation)이 존재하는 사람이라면 무조건 matchResult를 확인하여 내용을 반환하고 있더라고요.

public RoomParticipantResponses findParticipants(long roomId, long memberId) {
        List<Participation> participants = new java.util.ArrayList<>(
                // 방에 참여하고 있는 사람들을 모두 가져옴
                participationRepository.findAllByRoomId(roomId).stream()
                        .filter(participation -> participation.isNotMatchingMemberId(memberId))
                        .toList());
        Collections.shuffle(participants);

        return new RoomParticipantResponses(participants.stream()
                .limit(RANDOM_DISPLAY_PARTICIPANTS_SIZE)
                // 참여 기록마다 matchResult 확인
                .map(participation -> getRoomParticipantResponse(roomId, participation))
                .toList(), participants.size());
    }

    private RoomParticipantResponse getRoomParticipantResponse(long roomId, Participation participant) {
        return matchResultRepository.findAllByRevieweeIdAndRoomId(participant.getMembersId(), roomId).stream()
                .findFirst()
                .map(matchResult -> new RoomParticipantResponse(
                        matchResult.getReviewee().getGithubUserId(), matchResult.getReviewee().getUsername(), matchResult.getPrLink(), matchResult.getReviewee().getThumbnailUrl()))
                // PR이 없는 경우 깨짐
                .orElseThrow(() -> new CoreaException(ExceptionType.MEMBER_NOT_FOUND));
    }

이 과정에서 PR을 제출하지 않은 사람(= participation은 존재하지만 matchResult가 없음)의 경우 orElseThrow에서 MEMBER_NOT_FOUND를 반환하기 때문에

참여자 랜덤 리스트에 저 사람이 디스플레이 되어야 하는 사용자는 MEMBER_NOT_FOUND와 함께 방 접근 자체가 터져버리게 됩니다.

//participation 리스트를 생성하는 상위 단에서 아래 조건들은 필터링
private boolean isValidParticipant(Participation participation, long memberId) {
        return participation.isNotMatchingMemberId(memberId)
                && !participation.isReviewer()
                && !participation.isPullRequestNotSubmitted();
    }

따라서 모든 participation을 가져오는 대신

위 조건을 만족하는 사람들만 리스트로 넘겨주도록 로직 수정했습니다.

github-actions[bot] commented 1 week ago

Test Results

 48 files   48 suites   8s :stopwatch: 149 tests 145 :white_check_mark: 4 :zzz: 0 :x: 158 runs  154 :white_check_mark: 4 :zzz: 0 :x:

Results for commit 7468e55b.

:recycle: This comment has been updated with latest results.