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

docs(be): re-write admin problem module api docs #1296

Merged
merged 7 commits into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions backend/apps/admin/src/group/group.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,9 @@ export class GroupResolver {
}

@Mutation(() => String)
async issueInvitation(@Args('groupId', GroupIDPipe) id: number) {
async issueInvitation(
@Args('groupId', { type: () => Int }, GroupIDPipe) id: number
) {
try {
return await this.groupService.issueInvitation(id)
} catch (error) {
Expand All @@ -102,7 +104,9 @@ export class GroupResolver {
}

@Mutation(() => String)
async revokeInvitation(@Args('groupId', GroupIDPipe) id: number) {
async revokeInvitation(
@Args('groupId', { type: () => Int }, GroupIDPipe) id: number
) {
try {
return await this.groupService.revokeInvitation(id)
} catch (error) {
Expand Down
17 changes: 8 additions & 9 deletions backend/apps/admin/src/problem/problem.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import { AuthenticatedRequest } from '@libs/auth'
import { OPEN_SPACE_ID } from '@libs/constants'
import {
ConflictFoundException,
EntityNotExistException,
ForbiddenAccessException,
UnprocessableDataException
} from '@libs/exception'
Expand Down Expand Up @@ -197,15 +196,15 @@ export class ProblemResolver {
workbookId: number
) {
try {
return this.problemService.getWorkbookProblems(groupId, workbookId)
return await this.problemService.getWorkbookProblems(groupId, workbookId)
} catch (error) {
if (
error instanceof UnprocessableDataException ||
error instanceof ForbiddenAccessException
) {
throw error.convert2HTTPException()
} else if (error.code == 'P2025') {
throw new EntityNotExistException(error.message)
throw new NotFoundException(error.message)
}
this.logger.error(error)
throw new InternalServerErrorException(error.message)
Expand All @@ -226,7 +225,7 @@ export class ProblemResolver {
@Args('orders', { type: () => [Int] }, ParseArrayPipe) orders: number[]
) {
try {
return this.problemService.updateWorkbookProblemsOrder(
return await this.problemService.updateWorkbookProblemsOrder(
groupId,
workbookId,
orders
Expand All @@ -238,7 +237,7 @@ export class ProblemResolver {
) {
throw error.convert2HTTPException()
} else if (error.code == 'P2025') {
throw new EntityNotExistException(error.message)
throw new NotFoundException(error.message)
}
this.logger.error(error)
throw new InternalServerErrorException(error.message)
Expand All @@ -257,15 +256,15 @@ export class ProblemResolver {
contestId: number
) {
try {
return this.problemService.getContestProblems(groupId, contestId)
return await this.problemService.getContestProblems(groupId, contestId)
} catch (error) {
if (
error instanceof UnprocessableDataException ||
error instanceof ForbiddenAccessException
) {
throw error.convert2HTTPException()
} else if (error.code == 'P2025') {
throw new EntityNotExistException(error.message)
throw new NotFoundException(error.message)
}
this.logger.error(error)
throw new InternalServerErrorException(error.message)
Expand All @@ -285,7 +284,7 @@ export class ProblemResolver {
@Args('orders', { type: () => [Int] }, ParseArrayPipe) orders: number[]
) {
try {
return this.problemService.updateContestProblemsOrder(
return await this.problemService.updateContestProblemsOrder(
groupId,
contestId,
orders
Expand All @@ -297,7 +296,7 @@ export class ProblemResolver {
) {
throw error.convert2HTTPException()
} else if (error.code == 'P2025') {
throw new EntityNotExistException(error.message)
throw new NotFoundException(error.message)
}
this.logger.error(error)
throw new InternalServerErrorException(error.message)
Expand Down
78 changes: 78 additions & 0 deletions collection/admin/Problem/Create Problem/Succeed.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
meta {
name: Succeed
type: graphql
seq: 1
}

post {
url: {{gqlUrl}}
body: graphql
auth: none
}

body:graphql {
mutation CreateProblem($groupId: Int!, $input: CreateProblemInput!) {
createProblem(groupId: $groupId, input: $input) {
id
createdById
groupId
title
description
inputDescription
outputDescription
hint
}
}
}

body:graphql:vars {
{
"groupId": 1,
"input": {
"title": "createdProblem",
"description": "description",
"inputDescription": "input description",
"outputDescription": "output description",
"hint": "hint",
"template": {
"language": "Cpp",
"code": [
{
"id": 1,
"text": "int main() {}",
"locked": false
}
]
},
"languages": ["Cpp"],
"timeLimit": 0,
"memoryLimit": 0,
"difficulty": "Level2",
"source": "source",
"inputExamples": [],
"outputExamples": [],
"testcases": [
{
"input": "input",
"output": "output"
}
],
"tagIds": [1]
}
}
}

assert {
res.body.data.createProblem: isDefined
}

docs {
## Create Problem
Problem을 생성합니다.

### Error Cases
#### UNPROCESSABLE(1)
Problem은 최소 1개 이상의 프로그래밍 언어를 지원해야 합니다.
#### UNPROCESSABLE(2)
Problem은 Template에 존재하는 프로그래밍 언어를 지원해야 합니다.
}
68 changes: 68 additions & 0 deletions collection/admin/Problem/Create Problem/UNPROCESSABLE (1).bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
meta {
name: UNPROCESSABLE (1)
type: graphql
seq: 2
}

post {
url: {{gqlUrl}}
body: graphql
auth: none
}

body:graphql {
mutation CreateProblem($groupId: Int!, $input: CreateProblemInput!) {
createProblem(groupId: $groupId, input: $input) {
id
createdById
groupId
title
description
inputDescription
outputDescription
hint
}
}
}

body:graphql:vars {
{
"groupId": 1,
"input": {
"title": "createdProblem",
"description": "description",
"inputDescription": "input description",
"outputDescription": "output description",
"hint": "hint",
"template": {
"language": "Cpp",
"code": [
{
"id": 1,
"text": "int main() {}",
"locked": false
}
]
},
"languages": [],
"timeLimit": 0,
"memoryLimit": 0,
"difficulty": "Level2",
"source": "source",
"inputExamples": [],
"outputExamples": [],
"testcases": [
{
"input": "input",
"output": "output"
}
],
"tagIds": [1]
}
}
}

assert {
res.body.errors[0].extensions.code: eq UNPROCESSABLE
res.body.errors[0].message: eq A problem should support at least one language
}
68 changes: 68 additions & 0 deletions collection/admin/Problem/Create Problem/UNPROCESSABLE (2).bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
meta {
name: UNPROCESSABLE (2)
type: graphql
seq: 3
}

post {
url: {{gqlUrl}}
body: graphql
auth: none
}

body:graphql {
mutation CreateProblem($groupId: Int!, $input: CreateProblemInput!) {
createProblem(groupId: $groupId, input: $input) {
id
createdById
groupId
title
description
inputDescription
outputDescription
hint
}
}
}

body:graphql:vars {
{
"groupId": 1,
"input": {
"title": "createdProblem",
"description": "description",
"inputDescription": "input description",
"outputDescription": "output description",
"hint": "hint",
"template": {
"language": "Cpp",
"code": [
{
"id": 1,
"text": "int main() {}",
"locked": false
}
]
},
"languages": ["Python3"],
"timeLimit": 0,
"memoryLimit": 0,
"difficulty": "Level2",
"source": "source",
"inputExamples": [],
"outputExamples": [],
"testcases": [
{
"input": "input",
"output": "output"
}
],
"tagIds": [1]
}
}
}

assert {
res.body.errors[0].extensions.code: eq UNPROCESSABLE
res.body.errors[0].message: eq This problem does not support Cpp
}
38 changes: 38 additions & 0 deletions collection/admin/Problem/Delete a Problem/NOT_FOUND.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
meta {
name: NOT_FOUND
type: graphql
seq: 2
}

post {
url: {{gqlUrl}}
body: graphql
auth: none
}

body:graphql {
mutation DeleteProblem($groupId: Int!, $id: Int!) {
deleteProblem(groupId: $groupId, id: $id) {
id
createdById
groupId
title
description
inputDescription
outputDescription
hint
}
}
}

body:graphql:vars {
{
"groupId": 99999,
"id": 5
}
}

assert {
res.body.errors[0].extensions.code: eq NOT_FOUND
res.body.errors[0].message: eq No Problem found
}
Loading
Loading