Skip to content

Commit

Permalink
docs(be): add admin/client user docs (#1509)
Browse files Browse the repository at this point in the history
* refactor(be): add explicit type in graphQL

* docs(be): add admin user docs

* refactor(be): add explicit type in graphQL

* docs(be): add some user client api docs

* docs(be): add user client docs

* docs(be): modify documentation files

---------

Co-authored-by: Jaehyeon Kim <[email protected]>
  • Loading branch information
cho-to and Jaehyeon1020 authored Apr 1, 2024
1 parent 70014f3 commit ea3bdda
Show file tree
Hide file tree
Showing 55 changed files with 957 additions and 427 deletions.
19 changes: 7 additions & 12 deletions apps/backend/apps/admin/src/contest/contest.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import {
ParseBoolPipe
} from '@nestjs/common'
import { Args, Context, Int, Mutation, Query, Resolver } from '@nestjs/graphql'
import { ContestProblem } from '@generated'
import { Contest } from '@generated'
import { Contest, ContestProblem } from '@generated'
import { PrismaClientKnownRequestError } from '@prisma/client/runtime/library'
import { AuthenticatedRequest, UseRolesGuard } from '@libs/auth'
import { OPEN_SPACE_ID } from '@libs/constants'
Expand Down Expand Up @@ -38,7 +37,7 @@ export class ContestResolver {
take: number,
@Args(
'groupId',
{ type: () => Int, defaultValue: OPEN_SPACE_ID },
{ defaultValue: OPEN_SPACE_ID, type: () => Int },
GroupIDPipe
)
groupId: number,
Expand Down Expand Up @@ -70,7 +69,7 @@ export class ContestResolver {
@Args('input') input: CreateContestInput,
@Args(
'groupId',
{ type: () => Int, defaultValue: OPEN_SPACE_ID },
{ defaultValue: OPEN_SPACE_ID, type: () => Int },
GroupIDPipe
)
groupId: number,
Expand Down Expand Up @@ -116,8 +115,7 @@ export class ContestResolver {
@Mutation(() => Contest)
async deleteContest(
@Args('groupId', { type: () => Int }, GroupIDPipe) groupId: number,
@Args('contestId', { type: () => Int })
contestId: number
@Args('contestId', { type: () => Int }) contestId: number
) {
try {
return await this.contestService.deleteContest(groupId, contestId)
Expand All @@ -139,8 +137,7 @@ export class ContestResolver {
@Mutation(() => PublicizingRequest)
async createPublicizingRequest(
@Args('groupId', { type: () => Int }, GroupIDPipe) groupId: number,
@Args('contestId', { type: () => Int })
contestId: number
@Args('contestId', { type: () => Int }) contestId: number
) {
try {
return await this.contestService.createPublicizingRequest(
Expand All @@ -162,8 +159,7 @@ export class ContestResolver {
@Mutation(() => PublicizingResponse)
@UseRolesGuard()
async handlePublicizingRequest(
@Args('contestId', { type: () => Int })
contestId: number,
@Args('contestId', { type: () => Int }) contestId: number,
@Args('isAccepted', ParseBoolPipe) isAccepted: boolean
) {
try {
Expand All @@ -183,8 +179,7 @@ export class ContestResolver {
@Mutation(() => [ContestProblem])
async importProblemsToContest(
@Args('groupId', { type: () => Int }, GroupIDPipe) groupId: number,
@Args('contestId', { type: () => Int })
contestId: number,
@Args('contestId', { type: () => Int }) contestId: number,
@Args('problemIds', { type: () => [Int] }) problemIds: number[]
) {
try {
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/apps/admin/src/group/group.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export class GroupResolver {
async getGroups(
@Args('cursor', { nullable: true, type: () => Int }, CursorValidationPipe)
cursor: number | null,
@Args('take', { type: () => Int, defaultValue: 10 }) take: number
@Args('take', { defaultValue: 10, type: () => Int }) take: number
) {
return await this.groupService.getGroups(cursor, take)
}
Expand Down
20 changes: 9 additions & 11 deletions apps/backend/apps/admin/src/problem/problem.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export class ProblemResolver {
@Context('req') req: AuthenticatedRequest,
@Args(
'groupId',
{ type: () => Int, defaultValue: OPEN_SPACE_ID },
{ defaultValue: OPEN_SPACE_ID, type: () => Int },
GroupIDPipe
)
groupId: number,
Expand Down Expand Up @@ -84,7 +84,7 @@ export class ProblemResolver {
@Context('req') req: AuthenticatedRequest,
@Args(
'groupId',
{ type: () => Int, defaultValue: OPEN_SPACE_ID },
{ defaultValue: OPEN_SPACE_ID, type: () => Int },
GroupIDPipe
)
groupId: number,
Expand All @@ -109,13 +109,13 @@ export class ProblemResolver {
async getProblems(
@Args(
'groupId',
{ type: () => Int, defaultValue: OPEN_SPACE_ID },
{ defaultValue: OPEN_SPACE_ID, type: () => Int },
GroupIDPipe
)
groupId: number,
@Args('cursor', { nullable: true, type: () => Int }, CursorValidationPipe)
cursor: number | null,
@Args('take', { type: () => Int, defaultValue: 10 }) take: number,
@Args('take', { defaultValue: 10, type: () => Int }) take: number,
@Args('input') input: FilterProblemsInput
) {
return await this.problemService.getProblems(input, groupId, cursor, take)
Expand All @@ -125,7 +125,7 @@ export class ProblemResolver {
async getProblem(
@Args(
'groupId',
{ type: () => Int, defaultValue: OPEN_SPACE_ID },
{ defaultValue: OPEN_SPACE_ID, type: () => Int },
GroupIDPipe
)
groupId: number,
Expand Down Expand Up @@ -169,7 +169,7 @@ export class ProblemResolver {
async updateProblem(
@Args(
'groupId',
{ type: () => Int, defaultValue: OPEN_SPACE_ID },
{ defaultValue: OPEN_SPACE_ID, type: () => Int },
GroupIDPipe
)
groupId: number,
Expand Down Expand Up @@ -199,7 +199,7 @@ export class ProblemResolver {
async deleteProblem(
@Args(
'groupId',
{ type: () => Int, defaultValue: OPEN_SPACE_ID },
{ defaultValue: OPEN_SPACE_ID, type: () => Int },
GroupIDPipe
)
groupId: number,
Expand Down Expand Up @@ -310,8 +310,7 @@ export class WorkbookProblemResolver {
GroupIDPipe
)
groupId: number,
@Args('workbookId', { type: () => Int }, new RequiredIntPipe('workbookId'))
workbookId: number
@Args('workbookId', { type: () => Int }) workbookId: number
) {
try {
return await this.problemService.getWorkbookProblems(groupId, workbookId)
Expand All @@ -337,8 +336,7 @@ export class WorkbookProblemResolver {
GroupIDPipe
)
groupId: number,
@Args('workbookId', { type: () => Int }, new RequiredIntPipe('workbookId'))
workbookId: number,
@Args('workbookId', { type: () => Int }) workbookId: number,
// orders는 항상 workbookId에 해당하는 workbookProblems들이 모두 딸려 온다.
@Args('orders', { type: () => [Int] }, ParseArrayPipe) orders: number[]
) {
Expand Down
2 changes: 1 addition & 1 deletion apps/backend/apps/admin/src/user/user.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class UserResolver {
async getGroupMembers(
@Args(
'groupId',
{ type: () => Int, defaultValue: OPEN_SPACE_ID },
{ defaultValue: OPEN_SPACE_ID, type: () => Int },
GroupIDPipe
)
groupId: number,
Expand Down
8 changes: 8 additions & 0 deletions apps/backend/prisma/seed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ const createUsers = async () => {
realName: 'Yuljeon Kim'
}
})

// create user01 profile
await prisma.userProfile.create({
data: {
userId: users[0].id,
realName: 'Myeongryun Lee'
}
})
}

const createGroups = async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ post {
}

body:graphql {
mutation {
mutation CreatePublicizingRequest($contestId: Int!, $groupId: Int!){
createPublicizingRequest(
contestId: 3
groupId: 2
contestId: $contestId,
groupId: $groupId
) {
contestId
expireTime
Expand Down
30 changes: 30 additions & 0 deletions collection/admin/User/Delete Group Member/BAD_REQUEST(1).bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
meta {
name: BAD_REQUEST(1)
type: graphql
seq: 2
}

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

body:graphql {
mutation DeleteGroupMember($userId: Int!, $groupId: Int!) {
deleteGroupMember(userId: $userId, groupId: $groupId) {
userId
groupId
isGroupLeader
createTime
updateTime
}
}
}

body:graphql:vars {
{
"groupId": 2,
"userId": 99
}
}
30 changes: 30 additions & 0 deletions collection/admin/User/Delete Group Member/BAD_REQUEST(2).bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
meta {
name: BAD_REQUEST(2)
type: graphql
seq: 3
}

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

body:graphql {
mutation DeleteGroupMember($userId: Int!, $groupId: Int!) {
deleteGroupMember(userId: $userId, groupId: $groupId) {
userId
groupId
isGroupLeader
createTime
updateTime
}
}
}

body:graphql:vars {
{
"groupId": 3,
"userId": 3
}
}
57 changes: 57 additions & 0 deletions collection/admin/User/Delete Group Member/Succeed.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
meta {
name: Succeed
type: graphql
seq: 1
}

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

body:graphql {
mutation DeleteGroupMember($userId: Int!, $groupId: Int!) {
deleteGroupMember(userId: $userId, groupId: $groupId) {
userId
groupId
isGroupLeader
createTime
updateTime
}
}
}

body:graphql:vars {
{
"groupId": 2,
"userId": 5
}
}

assert {
res.body.data.DeleteGroupMember[0].userId: isDefined
res.body.data.DeleteGroupMember[0].groupId: isDefined
res.body.data.DeleteGroupMember[0].isGroupLeader: isBoolean
res.body.data.DeleteGroupMember[0].createTime: isDefined
res.body.data.DeleteGroupMember[0].updateTime: isDefined
}

docs {
## Delete Group Member
특정 Group Member를 삭제합니다.

### Args / Query / Params / Body
| 이름 | 타입 | 설명 |
|--|--|--|
|groupId|Int|삭제할 유저가 포함된 group의 Id|
|userId|Int|삭제하고 싶은 유저의 Id|

### Error Case

#### Not a Member
특정 group에 대해서 해당 userId의 유저가 포함되어 있지 않을 경우 (해당 userId의 유저가 존재하지 않을 때에도 위 에러로 반환됩니다.)

#### Delete Manager when num(Manager)=1
특정 group의 Manager가 삭제할 userId의 유저 한 명 뿐일 경우
}
35 changes: 0 additions & 35 deletions collection/admin/User/Get All Users/Succeed.bru

This file was deleted.

Loading

0 comments on commit ea3bdda

Please sign in to comment.