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

289 fix ranking api not working #291

Merged
merged 2 commits into from
Mar 14, 2024
Merged

Conversation

vimkim
Copy link
Collaborator

@vimkim vimkim commented Mar 8, 2024

Checklist

  • Testing: 앱이 잘 구동되는지 개발한 기능이 문제 없이 작동하는지 확인했나요?

간단한 유닛 테스트만 하고 통합 테스트 X. 프론트와 함께 할 예정. @glowisn

Description

 /**
   * returns an array of user id, username, and the number of accepted problems of the user, sorted by the number of accepted problems
   * @param code
   */
  async getRoomRankings(code: string) {
    Submission;
    User;
    const qb = this.roomRepository
      .createQueryBuilder('room')
      .where('room.code = :code', { code })
      .innerJoin('room.joinedUsers', 'roomUser')
      .innerJoin('roomUser.user', 'user')
      .innerJoin(
        'room.submissions',
        'submission',
        'submission.status = :status AND submission.user_id = user.id AND submission.alreadyAccepted = false',
        {
          status: Status.ACCEPTED,
        },
      )
      .select('user.id', 'userId')
      .addSelect('user.username', 'username')
      .addSelect('COUNT(submission.id)', 'acceptedCount')
      .addSelect('MAX(submission.submittedAt)', 'lastAcceptedAt')
      .groupBy('user.id')
      .orderBy('acceptedCount', 'DESC')
      .addOrderBy('lastAcceptedAt', 'ASC');

    const data = await qb.getRawMany();
    return { data };
  }
  1. 유저의 이름을 추출하기 위해 roomuser, user 테이블 조인
  2. 해당 룸에 제출된 'submission' 중, 최초 AC를 받은 제출들만 조인
  3. 가장 많은 문제를 맞춘 사람 -> 같으면 가장 빨리 마지막 문제를 AC를 받은 사람으로 정렬

Changes Made

현재 제출에 대하여

  1. 특정 유저가
  2. 특정 방에서
  3. 특정 문제에 대해
  4. '최초'로 AC를 받은 문제인지

여부를 판별하는 alreadyAccepted: boolean 칼럼을 submission entity에 추가하였습니다.

@vimkim vimkim self-assigned this Mar 8, 2024
@vimkim vimkim requested a review from glowisn March 8, 2024 17:25
Copy link
Collaborator

@glowisn glowisn left a comment

Choose a reason for hiding this comment

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

👍

@vimkim vimkim merged commit 9eee0c4 into main Mar 14, 2024
1 check passed
@vimkim vimkim deleted the 289-fix-ranking-api-not-working branch March 14, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix 랭킹 api 백엔드 제대로 동작 안 하는 버그 수정해야 합니다.
2 participants