From cd5ca510d9ee0513b5f8c9a5861b9a147e8aa761 Mon Sep 17 00:00:00 2001 From: DongHyeonWon Date: Thu, 26 Sep 2024 13:15:53 +0900 Subject: [PATCH] =?UTF-8?q?chore:=20swagger=20apibody=20=EC=84=A4=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/src/comment/comment.controller.ts | 3 ++- backend/src/comment/dto/create-comment.dto.ts | 5 +++++ backend/src/game/dto/create-game.dto.ts | 3 +++ backend/src/game/dto/gameResponse.dto.ts | 3 +-- backend/src/game/game.controller.ts | 12 ++++++++++-- 5 files changed, 21 insertions(+), 5 deletions(-) diff --git a/backend/src/comment/comment.controller.ts b/backend/src/comment/comment.controller.ts index c2bd8ae..b13a0af 100644 --- a/backend/src/comment/comment.controller.ts +++ b/backend/src/comment/comment.controller.ts @@ -4,7 +4,7 @@ import { CreateCommentDto } from 'src/comment/dto/create-comment.dto'; import { AuthGuard } from '@nestjs/passport'; import { Request } from 'express'; import { DeleteCommentDto } from 'src/comment/dto/delete-comment.dto'; -import { ApiOperation, ApiTags } from '@nestjs/swagger'; +import { ApiBody, ApiOperation, ApiTags } from '@nestjs/swagger'; @Controller('comment') @ApiTags('댓글 api') @@ -14,6 +14,7 @@ export class CommentController { @UseGuards(AuthGuard('jwt')) @Post() @ApiOperation({ summary: '아이템에 댓글을 입력합니다.' }) + @ApiBody({ type: CreateCommentDto }) async createComment( @Req() req: Request, @Body() createCommentDto: CreateCommentDto, diff --git a/backend/src/comment/dto/create-comment.dto.ts b/backend/src/comment/dto/create-comment.dto.ts index d45f17f..f520108 100644 --- a/backend/src/comment/dto/create-comment.dto.ts +++ b/backend/src/comment/dto/create-comment.dto.ts @@ -1,9 +1,14 @@ +import { ApiProperty } from '@nestjs/swagger'; import { IsNotEmpty } from 'class-validator'; export class CreateCommentDto { @IsNotEmpty() + @ApiProperty({ description: 'The text of the comment' }) comment_text: string; @IsNotEmpty() + @ApiProperty({ + description: 'The ID of the item to which the comment belongs', + }) item_id: string; } diff --git a/backend/src/game/dto/create-game.dto.ts b/backend/src/game/dto/create-game.dto.ts index 58d3650..0105696 100644 --- a/backend/src/game/dto/create-game.dto.ts +++ b/backend/src/game/dto/create-game.dto.ts @@ -1,9 +1,12 @@ +import { ApiProperty } from '@nestjs/swagger'; import { IsNotEmpty } from 'class-validator'; export class CreateGameDto { @IsNotEmpty() + @ApiProperty({ description: 'First item text' }) firstItemText: string; @IsNotEmpty() + @ApiProperty({ description: 'Second item text' }) secondItemText: string; } diff --git a/backend/src/game/dto/gameResponse.dto.ts b/backend/src/game/dto/gameResponse.dto.ts index 31bc1c7..3d44cf4 100644 --- a/backend/src/game/dto/gameResponse.dto.ts +++ b/backend/src/game/dto/gameResponse.dto.ts @@ -1,9 +1,8 @@ import { ApiProperty } from '@nestjs/swagger'; -import { GameDto } from 'src/game/dto/game.dto'; import { GetGamesItemDto } from 'src/item/dto/getGamesItem.dto'; export class GameResponseDto { - @ApiProperty({ type: [GameDto], description: '게임 데이터 목록' }) + @ApiProperty({ type: [GetGamesItemDto], description: '게임 데이터 목록' }) data: GetGamesItemDto[]; @ApiProperty({ description: '전체 게임 수', example: 100 }) diff --git a/backend/src/game/game.controller.ts b/backend/src/game/game.controller.ts index a143f3a..96beab5 100644 --- a/backend/src/game/game.controller.ts +++ b/backend/src/game/game.controller.ts @@ -14,7 +14,12 @@ import { GameService } from './game.service'; import { CreateGameDto } from 'src/game/dto/create-game.dto'; import { AuthGuard } from '@nestjs/passport'; import { Request } from 'express'; -import { ApiCreatedResponse, ApiOperation, ApiTags } from '@nestjs/swagger'; +import { + ApiBody, + ApiCreatedResponse, + ApiOperation, + ApiTags, +} from '@nestjs/swagger'; import { GameResponseDto } from 'src/game/dto/gameResponse.dto'; import { ItemsResponseDto } from 'src/item/dto/itemsResponse.dto'; import { GameDto } from 'src/game/dto/game.dto'; @@ -54,8 +59,11 @@ export class GameController { } @UseGuards(AuthGuard('jwt')) - @Post() @ApiOperation({ summary: '자신의 게임을 생성합니다.' }) + @ApiBody({ + type: CreateGameDto, + }) + @Post() async createGame( @Req() req: Request, @Body() createGameDto: CreateGameDto,