Skip to content

Commit

Permalink
docs(be): re-write admin problem module api docs (#1296)
Browse files Browse the repository at this point in the history
* docs(be): re-write admin problem module api docs

* fix(be): add missing await
- prisma 접근 코드에 await 처리 안되어있는 부분 수정
- docs 에러코드 작성

* docs(be): modify assert option

* docs(be): delete args table
- 새롭게 정해진 convention에 따라 args를 설명하는 표 삭제

* docs(be): modify assert

* fix(be): apply http error

* docs(be): modify api docs

Co-authored-by: cho-to <[email protected]>
Co-authored-by: SH9480P <[email protected]>
  • Loading branch information
3 people committed Feb 19, 2024
1 parent 8dc036f commit ff258d3
Show file tree
Hide file tree
Showing 24 changed files with 728 additions and 182 deletions.
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 @@ -14,7 +14,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 @@ -196,15 +195,15 @@ export class ProblemResolver {
@Args('workbookId', { type: () => Int }) 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 @@ -224,7 +223,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 @@ -236,7 +235,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 @@ -254,15 +253,15 @@ export class ProblemResolver {
@Args('contestId', { type: () => Int }) 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 @@ -281,7 +280,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 @@ -293,7 +292,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
}
37 changes: 36 additions & 1 deletion collection/admin/Problem/Delete a Problem/Succeed.bru
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,41 @@ meta {

post {
url: {{gqlUrl}}
body: none
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": 1,
"id": 5
}
}

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

docs {
## Delete Problem
Problem을 삭제합니다.

### Error Cases
#### NOT_FOUND
존재하는 id, groupId를 사용해야 합니다.
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
meta {
name: Error: No Contest found
name: NOT_FOUND
type: graphql
seq: 2
}
Expand Down Expand Up @@ -33,10 +33,5 @@ body:graphql:vars {

assert {
res.body.errors[0].message: eq No Contest found
}

docs {
# Error: No Contest found

- `contestId`가 `groupId`에 속하지 않으면, `No Contest found` Error를 반환합니다.
res.body.errors[0].extensions.code: eq NOT_FOUND
}
Loading

0 comments on commit ff258d3

Please sign in to comment.