Skip to content

Commit 0ce2798

Browse files
Merge pull request #557 from Alt-Org/docs/move-swagger-to-code-556
Moved swagger definitions from file to code
2 parents 37ed46d + ed9879c commit 0ce2798

File tree

94 files changed

+3131
-60
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+3131
-60
lines changed

src/auth/auth.controller.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { ThrowAuthErrorIfFound } from './decorator/ThrowAuthErrorIfFound.decorat
55
import { NoAuth } from './decorator/NoAuth.decorator';
66
import { AUTH_SERVICE } from './constant';
77
import BoxAuthService from './box/BoxAuthService';
8+
import ApiResponseDescription from '../common/swagger/response/ApiResponseDescription';
9+
import { ModelName } from '../common/enum/modelName.enum';
10+
import { ProfileDto } from '../profile/dto/profile.dto';
811

912
@NoAuth()
1013
@Controller('auth')
@@ -14,6 +17,21 @@ export class AuthController {
1417
private readonly authService: AuthService | BoxAuthService,
1518
) {}
1619

20+
/**
21+
* Log in to the system.
22+
*
23+
* @remarks After the profile with player was created, the user can log in to the system and get a JWT token to access resources.
24+
*
25+
* If the user provides the correct credentials, the access token will be returned, which should be used as a Bearer token in the Authorization header.
26+
*/
27+
@ApiResponseDescription({
28+
success: {
29+
status: 201,
30+
modelName: ModelName.CLAN,
31+
type: ProfileDto,
32+
},
33+
errors: [400, 401],
34+
})
1735
@Post('/signIn')
1836
@ThrowAuthErrorIfFound()
1937
public signIn(@Body() body: SignInDto) {

src/auth/dto/signIn.dto.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,19 @@ import AddType from '../../common/base/decorator/AddType.decorator';
33

44
@AddType('SignInDto')
55
export class SignInDto {
6+
/**
7+
* Unique username used by the player to sign in
8+
*
9+
* @example "DragonSlayer42"
10+
*/
611
@IsString()
712
username: string;
813

14+
/**
15+
* Password for player authentication
16+
*
17+
* @example "myStrongP@ssw0rd"
18+
*/
919
@IsString()
1020
password: string;
1121
}

src/box/box.controller.ts

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ import { BoxUser } from './auth/BoxUser';
3131
import { LoggedUser } from '../common/decorator/param/LoggedUser.decorator';
3232
import { BoxAuthGuard } from './auth/boxAuth.guard';
3333
import SessionStarterService from './sessionStarter/sessionStarter.service';
34+
import ApiResponseDescription from '../common/swagger/response/ApiResponseDescription';
35+
import { BoxDto } from './dto/box.dto';
3436

3537
@Controller('box')
3638
@UseGuards(BoxAuthGuard)
@@ -42,6 +44,24 @@ export class BoxController {
4244
private readonly sessionStarter: SessionStarterService,
4345
) {}
4446

47+
/**
48+
* Claim tester account.
49+
*
50+
* @remarks Tester can claim his/her account for the testing box.
51+
*
52+
* Notice that the tester should know the shared testers password in order to be able to clain the account.
53+
* This password is available after the group admin has started the session.
54+
*
55+
* Notice that the endpoint should be called only from browser, since a cookie should be added by the API
56+
*/
57+
@ApiResponseDescription({
58+
success: {
59+
status: 200,
60+
type: ClaimAccountResponseDto,
61+
},
62+
errors: [400, 403, 404],
63+
hasAuth: false,
64+
})
4565
@NoAuth()
4666
@Get('claim-account')
4767
@UniformResponse(undefined, ClaimAccountResponseDto)
@@ -65,6 +85,22 @@ export class BoxController {
6585
return res.send(data);
6686
}
6787

88+
/**
89+
* Create a testing box.
90+
*
91+
* @remarks Create a testing box.
92+
*
93+
* Notice that in order t0 create the testing box a group admin password need to be obtained from backend team
94+
*/
95+
@ApiResponseDescription({
96+
success: {
97+
status: 201,
98+
dto: CreatedBoxDto,
99+
modelName: ModelName.BOX,
100+
},
101+
errors: [400, 404],
102+
hasAuth: false,
103+
})
68104
@NoAuth()
69105
@Post()
70106
@UniformResponse(ModelName.BOX, CreatedBoxDto)
@@ -81,6 +117,21 @@ export class BoxController {
81117
return [{ ...createdBox, accessToken: groupAdminAccessToken }, null];
82118
}
83119

120+
/**
121+
* Reset testing box.
122+
*
123+
* @remarks Reset testing box data, which means removing all the data created during the testing session and returning the box state to the PREPARING stage.
124+
* For more information refer to the testing box documentation.
125+
*
126+
* Notice that only box admin can do the action.
127+
*/
128+
@ApiResponseDescription({
129+
success: {
130+
dto: CreatedBoxDto,
131+
modelName: ModelName.BOX,
132+
},
133+
errors: [401, 403, 404],
134+
})
84135
@Put('reset')
85136
@UniformResponse(ModelName.BOX)
86137
@IsGroupAdmin()
@@ -102,13 +153,41 @@ export class BoxController {
102153
return [{ ...createdBox, accessToken: groupAdminAccessToken }, null];
103154
}
104155

156+
/**
157+
* Delete box data.
158+
*
159+
* @remarks Delete box data associated with the logged-in user.
160+
*
161+
* Notice that the box can be removed only by the box admin.
162+
*/
163+
@ApiResponseDescription({
164+
success: {
165+
status: 204,
166+
},
167+
errors: [400, 404],
168+
})
105169
@Delete()
106170
@IsGroupAdmin()
107171
@UniformResponse()
108172
async deleteBoxAndAdmin(@LoggedUser() user: BoxUser) {
109173
return await this.service.deleteBox(user.box_id);
110174
}
111175

176+
/**
177+
* Start testing session
178+
*
179+
* @remarks Endpoint for starting testing session.
180+
*
181+
* Notice that only box admin can start a testing session.
182+
*
183+
* Notice that the minimum box data should be initialized at the moment of starting of testing session. That data is at least 2 tester accounts added.
184+
*/
185+
@ApiResponseDescription({
186+
success: {
187+
status: 204,
188+
},
189+
errors: [401, 403, 404],
190+
})
112191
@Post('/start')
113192
@UniformResponse(ModelName.BOX)
114193
@IsGroupAdmin()
@@ -117,6 +196,19 @@ export class BoxController {
117196
if (errors) return [null, errors];
118197
}
119198

199+
/**
200+
* Get box by _id, For time of development only
201+
*
202+
* @remarks Endpoint for getting box data by its _id
203+
*/
204+
@ApiResponseDescription({
205+
success: {
206+
dto: BoxDto,
207+
modelName: ModelName.BOX,
208+
},
209+
errors: [404],
210+
hasAuth: false,
211+
})
120212
//For time of development only
121213
@NoAuth()
122214
@Get('/:_id')
@@ -129,6 +221,18 @@ export class BoxController {
129221
return this.service.readOneById(param._id, { includeRefs });
130222
}
131223

224+
/**
225+
* Delete box by _id
226+
*
227+
* @remarks Endpoint for deleting a box by _id
228+
*/
229+
@ApiResponseDescription({
230+
success: {
231+
status: 204,
232+
},
233+
errors: [404],
234+
hasAuth: false,
235+
})
132236
//For time of development only
133237
@NoAuth()
134238
@Delete('/:_id')

src/box/box.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ export class BoxService {
170170
private getTesterAccount(box: BoxDto): Tester {
171171
const account = box.testers.find((tester) => {
172172
return tester.isClaimed !== true;
173-
});
173+
}) as unknown as Tester;
174174
if (!account) {
175175
throw new ServiceError({
176176
reason: SEReason.NOT_FOUND,

src/box/dailyTask/dailyTask.controller.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,32 @@ import { APIError } from '../../common/controller/APIError';
1313
import { APIErrorReason } from '../../common/controller/APIErrorReason';
1414
import BoxAuthHandler from '../auth/BoxAuthHandler';
1515
import { IsGroupAdmin } from '../auth/decorator/IsGroupAdmin';
16+
import ApiResponseDescription from '../../common/swagger/response/ApiResponseDescription';
17+
import SwaggerTags from '../../common/swagger/tags/SwaggerTags.decorator';
1618

19+
@SwaggerTags('Box')
1720
@Controller('/box/dailyTask')
1821
export class DailyTaskController {
1922
constructor(
2023
private readonly taskService: DailyTaskService,
2124
private readonly boxAuthHandler: BoxAuthHandler,
2225
) {}
2326

27+
/**
28+
* Add a daily task to box
29+
*
30+
* @remarks Add a daily task to array of predefined daily tasks.
31+
*
32+
* Notice that the logged-in player has to be a group admin
33+
*/
34+
@ApiResponseDescription({
35+
success: {
36+
status: 201,
37+
dto: PredefinedDailyTaskDto,
38+
modelName: ModelName.DAILY_TASK,
39+
},
40+
errors: [400, 401, 403, 404],
41+
})
2442
@Post()
2543
@IsGroupAdmin()
2644
@UniformResponse(ModelName.DAILY_TASK, PredefinedDailyTaskDto)
@@ -31,6 +49,22 @@ export class DailyTaskController {
3149
return this.taskService.addOne(user.box_id, body);
3250
}
3351

52+
/**
53+
* Add multiple daily tasks
54+
*
55+
* @remarks Add multiple daily tasks at once to daily tasks array of the box.
56+
*
57+
* Notice that only group admin can add the tasks.
58+
*/
59+
@ApiResponseDescription({
60+
success: {
61+
status: 201,
62+
dto: PredefinedDailyTaskDto,
63+
modelName: ModelName.DAILY_TASK,
64+
returnsArray: true,
65+
},
66+
errors: [400, 401, 403, 404],
67+
})
3468
@Post('/multiple')
3569
@IsGroupAdmin()
3670
@UniformResponse(ModelName.DAILY_TASK, PredefinedDailyTaskDto)
@@ -55,6 +89,19 @@ export class DailyTaskController {
5589
return this.taskService.addMultiple(user.box_id, body);
5690
}
5791

92+
/**
93+
* Update box daily task
94+
*
95+
* @remarks Update a predefined daily task of a box by its _id.
96+
*
97+
* Notice that only group admin can update the tasks
98+
*/
99+
@ApiResponseDescription({
100+
success: {
101+
status: 204,
102+
},
103+
errors: [400, 401, 403, 404],
104+
})
58105
@Put()
59106
@IsGroupAdmin()
60107
@UniformResponse(ModelName.DAILY_TASK)
@@ -69,6 +116,19 @@ export class DailyTaskController {
69116
if (errors) return [null, errors];
70117
}
71118

119+
/**
120+
* Delete box daily task by _id
121+
*
122+
* @remarks Delete daily task from predefined daily tasks array of the box.
123+
*
124+
* Notice that only group admin can delete the tasks
125+
*/
126+
@ApiResponseDescription({
127+
success: {
128+
status: 204,
129+
},
130+
errors: [400, 401, 403, 404],
131+
})
72132
@Delete('/:_id')
73133
@IsGroupAdmin()
74134
@UniformResponse(ModelName.DAILY_TASK)

src/box/dailyTask/dto/createPredefinedDailyTask.dto.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,51 @@ import { IsEnum, IsNumber, IsString } from 'class-validator';
22
import { ServerTaskName } from '../../../dailyTasks/enum/serverTaskName.enum';
33

44
export class CreatePredefinedDailyTaskDto {
5+
/**
6+
* Type of the predefined server task (e.g., collect items, win battles)
7+
*
8+
* @example "write_chat_message"
9+
*/
510
@IsEnum(ServerTaskName)
611
type: ServerTaskName;
712

13+
/**
14+
* Human-readable title of the task shown to players
15+
*
16+
* @example "Collect 10 Soul Orbs"
17+
*/
818
@IsString()
919
title: string;
1020

21+
/**
22+
* Required amount to complete the task (e.g., collect 10 orbs)
23+
*
24+
* @example 10
25+
*/
1126
@IsNumber()
1227
amount: number;
1328

29+
/**
30+
* Points awarded upon task completion
31+
*
32+
* @example 50
33+
*/
1434
@IsNumber()
1535
points: number;
1636

37+
/**
38+
* In-game currency reward for completing the task
39+
*
40+
* @example 100
41+
*/
1742
@IsNumber()
1843
coins: number;
1944

45+
/**
46+
* Time limit in minutes to complete the task (0 = no limit)
47+
*
48+
* @example 30
49+
*/
2050
@IsNumber()
2151
timeLimitMinutes: number;
2252
}

0 commit comments

Comments
 (0)