-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
export const isNil = (value: any): value is null | undefined => | ||
value === null || value === undefined; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
멘토님의 조언을 받아 isNil 생성
export interface RankingResponseDto { | ||
username: string; | ||
numberOfProblemsSolved: number; | ||
mostRecentCorrectSubmissionTime: string; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
합의한 Ranking Dto 추가. 현재 쓰는 것은 username 뿐입니다.
@Inject(forwardRef(() => SubmissionService)) | ||
private readonly submissionService: SubmissionService, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Room <-> Submission 간 상호 의존 추후 수정 예정
} | ||
@Get('ranking') | ||
async getRanking( | ||
@Query() roomSubmissionDto: RoomSubmissionDto, | ||
): Promise<RankingResponseDto[]> { | ||
return this.submissionService.getUsersRankingByRoomCode( | ||
roomSubmissionDto.roomCode, | ||
); | ||
} |
There was a problem hiding this comment.
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에 들어와 있습니다. 추후 수정 예정..
allSubmissions.each((index, element) => { | ||
const { tmpBojSolutionId, tmpStatus } = this.getEachSubmissionInfo( | ||
$, | ||
element, | ||
); | ||
const { tmpBojSolutionId, tmpStatus: unknownStatus } = | ||
this.getEachSubmissionInfo($, element); | ||
|
||
const tmpStatus = unknownStatus as keyof typeof BojResultsToStatus; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
implicitAny 없애기
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; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
첫번째 쿼리. 오류가 있어서 추후 수정 후 성능 비교 예정
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') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
두번째 쿼리, 예상대로 잘 동작하지만 조금 버그가 있어 디비 손 볼 예정
"moduleNameMapper": { | ||
"src/(.*)$": "<rootDir>/../src/$1", | ||
"test/(.*)$": "<rootDir>/$1" | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
jest를 baseDir 설정과 같이 돌리기 위한 설정
e2e 테스트를 추가하려다, 풀리퀘가 너무 길어질 것을 우려해서 우선 부분적으로 동작하는지만 확인하고,
추후 새로운 브랜치에서 e2e를 완성하고,
이후 다시 돌아와 보완할 계획입니다.