Skip to content

Commit

Permalink
chore: swagger apibody 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellol77 committed Sep 26, 2024
1 parent 2ddf470 commit cd5ca51
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion backend/src/comment/comment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -14,6 +14,7 @@ export class CommentController {
@UseGuards(AuthGuard('jwt'))
@Post()
@ApiOperation({ summary: '아이템에 댓글을 입력합니다.' })
@ApiBody({ type: CreateCommentDto })
async createComment(
@Req() req: Request,
@Body() createCommentDto: CreateCommentDto,
Expand Down
5 changes: 5 additions & 0 deletions backend/src/comment/dto/create-comment.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 3 additions & 0 deletions backend/src/game/dto/create-game.dto.ts
Original file line number Diff line number Diff line change
@@ -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;
}
3 changes: 1 addition & 2 deletions backend/src/game/dto/gameResponse.dto.ts
Original file line number Diff line number Diff line change
@@ -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 })
Expand Down
12 changes: 10 additions & 2 deletions backend/src/game/game.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit cd5ca51

Please sign in to comment.