Skip to content

Commit

Permalink
feat(be): implement search in contest overall apis (#2088)
Browse files Browse the repository at this point in the history
* feat(be): implement search in contest overall apis

* docs(be): add description about searching name

* chore(be): add exception handling logic

* docs(be): change searching-name condition
  • Loading branch information
Jaehyeon1020 authored Sep 22, 2024
1 parent a350cbc commit 464ff5f
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 27 deletions.
16 changes: 11 additions & 5 deletions apps/backend/apps/admin/src/contest/contest.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,21 @@ export class ContestResolver {
*/
@Query(() => [UserContestScoreSummaryWithUserInfo])
async getContestScoreSummaries(
@Args('take', { type: () => Int, defaultValue: 10 }) take: number,
@Args('contestId', { type: () => Int }) contestId: number,
@Args('cursor', { type: () => Int, nullable: true }) cursor: number | null
@Args('contestId', { type: () => Int, nullable: false }, IDValidationPipe)
contestId: number,
@Args('take', { type: () => Int, defaultValue: 10 })
take: number,
@Args('cursor', { type: () => Int, nullable: true }, CursorValidationPipe)
cursor: number | null,
@Args('searchingName', { type: () => String, nullable: true })
searchingName?: string
) {
try {
return await this.contestService.getContestScoreSummaries(
take,
contestId,
cursor
take,
cursor,
searchingName
)
} catch (error) {
if (error instanceof EntityNotExistException) {
Expand Down
44 changes: 31 additions & 13 deletions apps/backend/apps/admin/src/contest/contest.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -766,17 +766,24 @@ export class ContestService {
const problemId = submission.problemId
if (problemId in latestSubmissions) continue

const maxScore = (
await this.prisma.contestProblem.findUniqueOrThrow({
where: {
// eslint-disable-next-line @typescript-eslint/naming-convention
contestId_problemId: {
contestId: submission.contestId!,
problemId: submission.problemId
}
const contestProblem = await this.prisma.contestProblem.findUnique({
where: {
// eslint-disable-next-line @typescript-eslint/naming-convention
contestId_problemId: {
contestId: submission.contestId!,
problemId: submission.problemId
}
})
).score
},
select: {
score: true
}
})

if (!contestProblem) {
throw new EntityNotExistException('contestProblem')
}

const maxScore = contestProblem.score

latestSubmissions[problemId] = {
result: submission.result as ResultStatus,
Expand All @@ -789,9 +796,10 @@ export class ContestService {
}

async getContestScoreSummaries(
take: number,
contestId: number,
cursor: number | null
take: number,
cursor: number | null,
searchingName?: string
) {
const paginator = this.prisma.getPaginator(cursor)

Expand All @@ -801,7 +809,17 @@ export class ContestService {
contestId,
userId: {
not: null
}
},
user: searchingName
? {
userProfile: {
realName: {
contains: searchingName,
mode: 'insensitive'
}
}
}
: undefined
},
take,
include: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ export class GetContestSubmissionsInput {

@Field(() => Int, { nullable: true })
problemId?: number

@Field(() => String, { nullable: true })
searchingName?: string
}
16 changes: 13 additions & 3 deletions apps/backend/apps/admin/src/submission/submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@ export class SubmissionService {
) {
const paginator = this.prisma.getPaginator(cursor)

const { contestId, problemId } = input
const { contestId, problemId, searchingName } = input
const contestSubmissions = await this.prisma.submission.findMany({
...paginator,
take,
where: {
contestId,
problemId
problemId,
user: searchingName
? {
userProfile: {
realName: {
contains: searchingName,
mode: 'insensitive'
}
}
}
: undefined
},
include: {
user: {
Expand All @@ -44,7 +54,7 @@ export class SubmissionService {
contestProblem: {
where: {
contestId,
problemId: problemId ?? undefined
problemId
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ body:graphql {
body:graphql:vars {
{
"contestId": 1,
"userId": 4
// "problemId": 1
"userId": 1
// "searchingName": "lee"
}
}

Expand All @@ -44,4 +44,9 @@ docs {
* Contest에 참여한 User와, 점수 요약을 함께 불러옵니다.
* Contest Overall 페이지의 Participants 탭의 정보
* https://github.com/skkuding/codedang/pull/2029

#### 필요 인자
| `contestId` | `searchingName?` | `take?` | `cursor?` |
|----------|--------|----------|------------|
| 불러올 Contest의 id | 필터링할 User의 realName(없으면 모든 유저) | Pagination 구현을 위함(default: 10) | Pagination 구현을 위함(default: null) |
}
16 changes: 12 additions & 4 deletions collection/admin/Submission/Get Contest Submissions/Succeed.bru
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ body:graphql {
body:graphql:vars {
{
"input": {
"contestId": 1
"contestId": 1,
"problemId": 1,
"searchingName": "lee"
},
"take": 10
}
Expand All @@ -53,7 +55,13 @@ docs {
- https://github.com/skkuding/codedang/pull/1924

#### 필요 인자
|`input`|`take`|`cursor`|
|----------|----------|----------|
| `contestId`: 제출 내역을 불러올 Contest의 ID입니다. `problemId?`: 제출된 내역 중 특정 Problem의 제출만을 필터링 할 수 있습니다.| pagination 구현을 위함 | pagination 구현을 위함 |
| `input` | `take` | `cursor` |
|----------|--------|----------|
| 밑에서 설명 | Pagination 구현을 위함 | Pagination 구현을 위함 |

`input`
- `contestId`: 제출 내역을 불러올 Contest의 ID
- `problemId?`: 제출된 내역 중 특정 Problem의 제출만 필터링
- `searchingName?`: 필터링할 User의 realName(없으면 모든 유저)

}

0 comments on commit 464ff5f

Please sign in to comment.