Skip to content

Commit

Permalink
๐Ÿ“ update api docs and fix http status code #114
Browse files Browse the repository at this point in the history
update api docs and fix http status code #114
  • Loading branch information
sichoi42 committed Nov 6, 2022
1 parent eb9e506 commit 0fa351e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 25 deletions.
9 changes: 2 additions & 7 deletions backend/src/v3/lent/lent.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,16 @@ export class LentController {
@ApiCreatedResponse({
description: '๋Œ€์—ฌ์— ์„ฑ๊ณต ์‹œ, 201 Created๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
})
@ApiNotFoundResponse({
description: 'ํ•ด๋‹น ์บ๋น„๋„ท์ด๋‚˜ ์œ ์ €๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด, 404 Not Found๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
})
@ApiBadRequestResponse({
description:
'์ด๋ฏธ ๋Œ€์—ฌ์ค‘์ธ ์‚ฌ๋ฌผํ•จ์ด ์žˆ๋Š” ๊ฒฝ์šฐ, 400 Bad Request๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
description:'ํ•ด๋‹น ์บ๋น„๋„ท์ด๋‚˜ ์œ ์ €๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ or ํ•ด๋‹น ์œ ์ €๊ฐ€ ์ด๋ฏธ ๋Œ€์—ฌ์ค‘์ธ ์‚ฌ๋ฌผํ•จ์ด ์žˆ๋Š” ๊ฒฝ์šฐ, 400 Bad Request๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
})
@ApiResponse({
status: HttpStatus.I_AM_A_TEAPOT,
description:
"๋™์•„๋ฆฌ ์‚ฌ๋ฌผํ•จ์„ ๋Œ€์—ฌ ์‹œ๋„ํ•œ ๊ฒฝ์šฐ, 418 I'm a teapot์„ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.",
})
@ApiConflictResponse({
description: `์ž”์—ฌ ์ž๋ฆฌ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ, ์—ฐ์ฒด ์‚ฌ๋ฌผํ•จ์„ ๋Œ€์—ฌ ์‹œ๋„ํ•œ ๊ฒฝ์šฐ,
์ž„์‹œ ๋ฐด ์‚ฌ๋ฌผํ•จ์ด๋‚˜ ๊ณ ์žฅ ์‚ฌ๋ฌผํ•จ์„ ๋Œ€์—ฌ ์‹œ๋„ํ•œ ๊ฒฝ์šฐ 409 Conflict๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.`,
description: 'ํ•ด๋‹น ์บ๋น„๋„ท์— ์ž”์—ฌ ์ž๋ฆฌ๊ฐ€ ์—†๋Š” ๊ฒฝ์šฐ or ์—ฐ์ฒด ์‚ฌ๋ฌผํ•จ์„ ๋Œ€์—ฌ ์‹œ๋„ํ•œ ๊ฒฝ์šฐ or ์ž„์‹œ ๋ฐด ์‚ฌ๋ฌผํ•จ์ด๋‚˜ ๊ณ ์žฅ ์‚ฌ๋ฌผํ•จ์„ ๋Œ€์—ฌ ์‹œ๋„ํ•œ ๊ฒฝ์šฐ, 409 Conflict๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
})
@Post('/cabinet/:cabinet_id/:user_id')
@HttpCode(HttpStatus.CREATED)
Expand Down
4 changes: 2 additions & 2 deletions backend/src/v3/lent/lent.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export class LentService {
if (!user) {
throw new HttpException(
`๐Ÿšจ ํ•ด๋‹น ์œ ์ €๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๐Ÿšจ`,
HttpStatus.NOT_FOUND,
HttpStatus.BAD_REQUEST,
);
}
// ์บ๋น„๋„ท์ด ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ
if (!await this.cabinetService.isCabinetExist(cabinet_id)) {
throw new HttpException(
`๐Ÿšจ ํ•ด๋‹น ์บ๋น„๋„ท์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๐Ÿšจ`,
HttpStatus.NOT_FOUND,
HttpStatus.BAD_REQUEST,
);
}
// ์œ ์ €๊ฐ€ ๋Œ€์—ฌํ•œ ์‚ฌ๋ฌผํ•จ ํ™•์ธ
Expand Down
1 change: 0 additions & 1 deletion backend/src/v3/return/return.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export class ReturnTools {
@Inject('IReturnRepository')
private returnRepository: IReturnRepository,
private cabinetService: CabinetService,
@Inject(forwardRef(() => ReturnService))
private banService: BanService,
) {}

Expand Down
15 changes: 4 additions & 11 deletions backend/src/v3/return/return.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,9 @@ export class ReturnController {
@ApiNoContentResponse({
description: '๋ฐ˜๋‚ฉ์— ์„ฑ๊ณต ์‹œ, 204 No Content๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
})
@ApiNotFoundResponse({
description: 'ํ•ด๋‹น ์œ ์ €๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด, 404 Not Found๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
})
@ApiBadRequestResponse({
description:
'๋Œ€์—ฌ์ค‘์ธ ์‚ฌ๋ฌผํ•จ์ด ์—†๋Š” ๊ฒฝ์šฐ, 400 Bad Request๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
'ํ•ด๋‹น ์œ ์ €๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ ๋Œ€์—ฌ์ค‘์ธ ์‚ฌ๋ฌผํ•จ์ด ์—†๋Š” ๊ฒฝ์šฐ, 400 Bad Request๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
})
@Delete('/user/:user_id')
@HttpCode(HttpStatus.NO_CONTENT)
Expand All @@ -59,12 +56,9 @@ export class ReturnController {
@ApiNoContentResponse({
description: '๋ฐ˜๋‚ฉ์— ์„ฑ๊ณต ์‹œ, 204 No Content๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
})
@ApiNotFoundResponse({
description: 'ํ•ด๋‹น ์บ๋น„๋„ท์ด ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด, 404 Not Found๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
})
@ApiBadRequestResponse({
description:
'ํ•ด๋‹น ์‚ฌ๋ฌผํ•จ์„ ๋Œ€์—ฌ์ค‘์ธ ์œ ์ €๊ฐ€ ์—†๋‹ค๋ฉด, 400 Bad Request๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
'ํ•ด๋‹น ์บ๋น„๋„ท์ด ์กด์žฌํ•˜์ง€ ์•Š๊ฑฐ๋‚˜ ํ•ด๋‹น ์‚ฌ๋ฌผํ•จ์„ ๋Œ€์—ฌ์ค‘์ธ ์œ ์ €๊ฐ€ ์—†๋‹ค๋ฉด, 400 Bad Request๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.',
})
@Delete('/cabinet/:cabinet_id')
@HttpCode(HttpStatus.NO_CONTENT)
Expand Down Expand Up @@ -93,8 +87,7 @@ export class ReturnController {
})
@ApiBadRequestResponse({
type: ReturnBundleFailedResponseDto,
description: `๋Œ€์—ฌ์ค‘์ธ ์‚ฌ๋ฌผํ•จ์ด ์—†๋Š” ์œ ์ €๊ฐ€ ์žˆ๊ฑฐ๋‚˜ ๋Œ€์—ฌ์ค‘์ธ ์œ ์ €๊ฐ€ ์—†๋Š” ์‚ฌ๋ฌผํ•จ์ด ์žˆ๋Š” ๊ฒฝ์šฐ, 400 Bad Request๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค.
์ด๋•Œ response body๋กœ ์ฒ˜๋ฆฌ์— ์‹คํŒจํ•œ user_id๋‚˜ cabinet_id์˜ ๋ฐฐ์—ด์„ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.`,
description: '์กด์žฌํ•˜์ง€ ์•Š๋Š” ์œ ์ €์ด๊ฑฐ๋‚˜ ๋Œ€์—ฌ์ค‘์ธ ์‚ฌ๋ฌผํ•จ์ด ์—†๋Š” ์œ ์ €๊ฐ€ ํฌํ•จ๋˜์–ด ์žˆ๋Š” ๊ฒฝ์šฐ or ์กด์žฌํ•˜์ง€ ์•Š๋Š” ์‚ฌ๋ฌผํ•จ์ด๊ฑฐ๋‚˜ ์œ ์ €๊ฐ€ ๋Œ€์—ฌ์ค‘์ด์ง€ ์•Š์€ ์‚ฌ๋ฌผํ•จ์ด ํฌํ•จ๋˜์–ด ์žˆ๋Š” ๊ฒฝ์šฐ, 400 Bad Request๋ฅผ ์‘๋‹ตํ•ฉ๋‹ˆ๋‹ค. ์ด๋•Œ response body๋กœ ์ฒ˜๋ฆฌ์— ์‹คํŒจํ•œ user_id๋‚˜ cabinet_id์˜ ๋ฐฐ์—ด์„ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.',
})
@ApiBody({ type: ReturnBundleDataDto })
@Delete('bundle/cabinet')
Expand All @@ -115,7 +108,7 @@ export class ReturnController {
this.logger.debug(`Called ${this.returnBundle.name}`);
return await this.returnService.returnBundle(users, cabinets);
} catch (err) {
this.logger.error(err);
this.logger.error(err, err.response);
if (err instanceof HttpException) {
throw err;
} else {
Expand Down
15 changes: 11 additions & 4 deletions backend/src/v3/return/return.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export class ReturnService {
@Inject('IReturnRepository') private returnRepository: IReturnRepository,
private userService: UserService,
private lentTools: LentTools,
@Inject(forwardRef(() => ReturnTools))
private returnTools: ReturnTools,
private cabinetService: CabinetService,
) {}

async returnUserCabinet(user_id: number): Promise<void> {
Expand All @@ -27,7 +27,7 @@ export class ReturnService {
if (!user) {
throw new HttpException(
`๐Ÿšจ ํ•ด๋‹น ์œ ์ €๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๐Ÿšจ`,
HttpStatus.NOT_FOUND,
HttpStatus.BAD_REQUEST,
);
}
// 1. ํ•ด๋‹น ์œ ์ €๊ฐ€ ๋Œ€์—ฌ์ค‘์ธ cabinet_id๋ฅผ ๊ฐ€์ ธ์˜จ๋‹ค.
Expand All @@ -36,8 +36,8 @@ export class ReturnService {
);
if (cabinet_id === null) {
throw new HttpException(
`${user.intra_id} doesn't lent cabinet!`,
HttpStatus.FORBIDDEN,
`๐Ÿšจ ํ•ด๋‹น ์œ ์ €๊ฐ€ ๋Œ€์—ฌ์ค‘์ธ ์‚ฌ๋ฌผํ•จ์ด ์—†์Šต๋‹ˆ๋‹ค. ๐Ÿšจ`,
HttpStatus.BAD_REQUEST,
);
}
const lent = await this.returnTools.returnStateTransition(
Expand All @@ -53,6 +53,13 @@ export class ReturnService {
async returnCabinet(cabinet_id: number): Promise<void> {
this.logger.debug(`Called ${ReturnService.name} ${this.returnCabinet.name}`);
try {
// ์บ๋น„๋„ท์ด ์กด์žฌํ•˜๋Š”์ง€ ํ™•์ธ
if (!await this.cabinetService.isCabinetExist(cabinet_id)) {
throw new HttpException(
`๐Ÿšจ ํ•ด๋‹น ์บ๋น„๋„ท์ด ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค. ๐Ÿšจ`,
HttpStatus.BAD_REQUEST,
);
}
const users = await this.returnRepository.getUsersByCabinetId(cabinet_id);
if (users === null) {
throw new HttpException(
Expand Down

0 comments on commit 0fa351e

Please sign in to comment.