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(ranking-api): ranking api 부분 완성 #264

Merged
merged 26 commits into from
Feb 10, 2024
Merged

Conversation

vimkim
Copy link
Collaborator

@vimkim vimkim commented Feb 7, 2024

e2e 테스트를 추가하려다, 풀리퀘가 너무 길어질 것을 우려해서 우선 부분적으로 동작하는지만 확인하고,
추후 새로운 브랜치에서 e2e를 완성하고,
이후 다시 돌아와 보완할 계획입니다.

@vimkim vimkim linked an issue Feb 7, 2024 that may be closed by this pull request
@vimkim vimkim self-assigned this Feb 8, 2024
@vimkim vimkim marked this pull request as ready for review February 8, 2024 07:32
@vimkim vimkim marked this pull request as draft February 10, 2024 13:54
Comment on lines +1 to +2
export const isNil = (value: any): value is null | undefined =>
value === null || value === undefined;
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

멘토님의 조언을 받아 isNil 생성

Comment on lines +1 to +5
export interface RankingResponseDto {
username: string;
numberOfProblemsSolved: number;
mostRecentCorrectSubmissionTime: string;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

합의한 Ranking Dto 추가. 현재 쓰는 것은 username 뿐입니다.

Comment on lines +32 to +33
@Inject(forwardRef(() => SubmissionService))
private readonly submissionService: SubmissionService,
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Room <-> Submission 간 상호 의존 추후 수정 예정

Comment on lines 30 to +38
}
@Get('ranking')
async getRanking(
@Query() roomSubmissionDto: RoomSubmissionDto,
): Promise<RankingResponseDto[]> {
return this.submissionService.getUsersRankingByRoomCode(
roomSubmissionDto.roomCode,
);
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

기존에 합의한 /room/:code/ranking api가 현재 nest js dependency injection 의 한계로 submission에 들어와 있습니다. 추후 수정 예정..

Comment on lines 130 to 135
allSubmissions.each((index, element) => {
const { tmpBojSolutionId, tmpStatus } = this.getEachSubmissionInfo(
$,
element,
);
const { tmpBojSolutionId, tmpStatus: unknownStatus } =
this.getEachSubmissionInfo($, element);

const tmpStatus = unknownStatus as keyof typeof BojResultsToStatus;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

implicitAny 없애기

Comment on lines +198 to +217
async getSubmissionsByRoomCodeGroupByUsers(
roomCode: string,
): Promise<RankingResponseDto[]> {
const qb = this.submissionRepository
.createQueryBuilder('s')
.innerJoin('s.room', 'r', 'r.code = :roomCode', { roomCode })
.innerJoin('s.user', 'u')
.where('s.status = :status', { status: Status.ACCEPTED })
.addSelect('u.username', 'username')
.addSelect('COUNT(*)', 'numberOfProblemsSolved')
.addSelect('MAX(s.submittedAt)', 'mostRecentCorrectSubmissionTime');

this.explainQuery(...qb.getQueryAndParameters());

const results = await qb.getRawMany();
results.forEach((res) => {
res.numberOfProblemsSolved = Number(res.numberOfProblemsSolved);
});
return results;
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

첫번째 쿼리. 오류가 있어서 추후 수정 후 성능 비교 예정

Comment on lines +219 to +229
async getUsersRankingByRoomCode(code: string): Promise<RankingResponseDto[]> {
const qb = this.entityManager
.createQueryBuilder(Room, 'room')
.where('room.code = :code', { code })
.select('user.username', 'username')
.addSelect('COUNT(*)', 'numberOfProblemsSolved')
.addSelect(
'MAX(submission.submittedAt)',
'mostRecentCorrectSubmissionTime',
)
.innerJoin('room.joinedUsers', 'roomUser')
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

두번째 쿼리, 예상대로 잘 동작하지만 조금 버그가 있어 디비 손 볼 예정

Comment on lines +4 to +7
"moduleNameMapper": {
"src/(.*)$": "<rootDir>/../src/$1",
"test/(.*)$": "<rootDir>/$1"
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

jest를 baseDir 설정과 같이 돌리기 위한 설정

@vimkim vimkim changed the title feat(ranking-api): ranking api 완성 feat(ranking-api): ranking api 미완성 Feb 10, 2024
@vimkim vimkim marked this pull request as ready for review February 10, 2024 15:41
@vimkim vimkim changed the title feat(ranking-api): ranking api 미완성 feat(ranking-api): ranking api 부분 완성 Feb 10, 2024
@vimkim vimkim merged commit 3694f3e into main Feb 10, 2024
2 checks passed
@vimkim vimkim deleted the 263-featranking-ranking-api branch February 10, 2024 15:43
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.

Feat(ranking): ranking api 제공
1 participant