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 authored Feb 6, 2024
1 parent 9b57a2a commit 23d53b5
Show file tree
Hide file tree
Showing 25 changed files with 734 additions and 184 deletions.
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 @@ -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 @@ -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

0 comments on commit 23d53b5

Please sign in to comment.