-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 유저 게임 불러오기 api 추가 * feat: 게임 삭제 api 추가 * feat: 댓글 좋아요 및 좋아요 취소 api 추가 * fix: create-comment dto 수정 및 body 데코레이터 추가 * fix: create-game dto 수정 * fix: ParseIntPipe 추가 * feat: likeCount 추가 * feat: CommentDto 추가 * feat: find comment에likeCount 추가 * chore: swagger ApiProperty 설정 추가 * feat: swagger 설정 및 response dto 추가
- Loading branch information
Showing
23 changed files
with
460 additions
and
44 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,28 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
|
||
export class CommentDto { | ||
@IsNotEmpty() | ||
@ApiProperty({ description: 'The ID of the comment' }) | ||
comment_id: number; | ||
|
||
@IsNotEmpty() | ||
@ApiProperty({ description: 'The text of the comment' }) | ||
comment_text: string; | ||
|
||
@IsNotEmpty() | ||
@ApiProperty({ description: 'The date when the comment was created' }) | ||
created_at: Date; | ||
|
||
@IsNotEmpty() | ||
@ApiProperty({ description: 'The date when the comment was last updated' }) | ||
updated_at: Date; | ||
|
||
@IsNotEmpty() | ||
@ApiProperty({ description: 'The user who made the comment', type: String }) | ||
user: string; | ||
|
||
@IsNotEmpty() | ||
@ApiProperty({ description: 'The number of likes the comment has received' }) | ||
likeCount: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,4 @@ export class CreateGameDto { | |
|
||
@IsNotEmpty() | ||
secondItemText: string; | ||
|
||
@IsNotEmpty() | ||
user_id: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { IsNotEmpty } from 'class-validator'; | ||
|
||
export class GameDto { | ||
@IsNotEmpty() | ||
@ApiProperty({ description: 'The ID of the game' }) | ||
game_id: number; | ||
|
||
@IsNotEmpty() | ||
@ApiProperty({ description: 'First item text' }) | ||
first_item_text: string; | ||
|
||
@IsNotEmpty() | ||
@ApiProperty({ description: 'Second item text' }) | ||
second_item_text: string; | ||
|
||
@IsNotEmpty() | ||
@ApiProperty({ description: 'Created date' }) | ||
created_at: Date; | ||
|
||
@IsNotEmpty() | ||
@ApiProperty({ description: 'The user who made the game', type: Number }) | ||
user_id: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ApiProperty } from '@nestjs/swagger'; | ||
import { GameDto } from 'src/game/dto/game.dto'; | ||
|
||
export class GameResponseDto { | ||
@ApiProperty({ type: [GameDto], description: '게임 데이터 목록' }) | ||
data: GameDto[]; | ||
|
||
@ApiProperty({ description: '전체 게임 수', example: 100 }) | ||
total: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,95 @@ | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Logger, | ||
Param, | ||
ParseIntPipe, | ||
Post, | ||
Query, | ||
Req, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { GameService } from './game.service'; | ||
import { Game } from 'src/game/game.entity'; | ||
import { CreateGameDto } from 'src/game/dto/create-game.dto'; | ||
import { AuthGuard } from '@nestjs/passport'; | ||
import { Item } from 'src/item/item.entity'; | ||
import { Request } from 'express'; | ||
import { 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'; | ||
|
||
@Controller('game') | ||
@ApiTags('게임 api') | ||
export class GameController { | ||
private logger = new Logger('GameController'); | ||
constructor(private readonly gameService: GameService) {} | ||
|
||
@Get() | ||
@ApiOperation({ summary: '모든 게임들을 불러옵니다.' }) | ||
@ApiCreatedResponse({ | ||
description: '모든 게임들을 불러옵니다.', | ||
type: GameResponseDto, | ||
}) | ||
async findAll( | ||
@Query('page') page: number = 1, // 페이지 번호 | ||
@Query('limit') limit: number = 10, // 페이지당 항목 수 | ||
): Promise<{ data: Game[]; total: number }> { | ||
): Promise<GameResponseDto> { | ||
this.logger.log('Handling Find All Games request'); | ||
const games = await this.gameService.findAll({ page, limit }); | ||
const total = await this.gameService.countGames(); // 전체 게임 수 계산 | ||
return { data: games, total }; | ||
} | ||
|
||
@Get(':game_id/items') | ||
async getItemsByGameId(@Param('game_id') game_id: number): Promise<Item[]> { | ||
@ApiOperation({ summary: '게임의 아이템들을 모두 가져옵니다.' }) | ||
@ApiCreatedResponse({ | ||
description: '게임의 아이템들을 모두 가져옵니다.', | ||
type: ItemsResponseDto, | ||
}) | ||
async getItemsByGameId( | ||
@Param('game_id') game_id: number, | ||
): Promise<ItemsResponseDto> { | ||
return this.gameService.findItemsByGameId(game_id); | ||
} | ||
|
||
@UseGuards(AuthGuard('jwt')) | ||
@Post() | ||
@ApiOperation({ summary: '자신의 게임을 생성합니다.' }) | ||
async createGame( | ||
@Req() req: Request, | ||
@Body() createGameDto: CreateGameDto, | ||
): Promise<Game> { | ||
): Promise<void> { | ||
const kakaoId = req.user.kakaoId; | ||
this.logger.log('Handling create game'); | ||
return this.gameService.createGame({ ...createGameDto, user_id: kakaoId }); | ||
return this.gameService.createGame(kakaoId, createGameDto); | ||
} | ||
|
||
@UseGuards(AuthGuard('jwt')) | ||
@Get('user') | ||
@ApiOperation({ summary: '사용자가 만든 게임들을 가져옵니다.' }) | ||
@ApiCreatedResponse({ | ||
description: '자신이 만든 게임들을 가져옵니다.', | ||
type: [GameDto], | ||
}) | ||
async findGamesByUserId( | ||
@Req() req: Request, | ||
@Query('page') page: number = 1, // 페이지 번호 | ||
@Query('limit') limit: number = 10, // 페이지당 항목 수 | ||
): Promise<GameDto[]> { | ||
const kakaoId = req.user.kakaoId; | ||
return this.gameService.findGamesByUserId(kakaoId, page, limit); | ||
} | ||
|
||
@UseGuards(AuthGuard('jwt')) | ||
@Delete(':game_id') | ||
@ApiOperation({ summary: '자신의 게임을 삭제합니다.' }) | ||
async deleteGame( | ||
@Req() req: Request, | ||
@Param('game_id', ParseIntPipe) game_id: number, | ||
): Promise<void> { | ||
const kakaoId = req.user.kakaoId; | ||
return this.gameService.deleteGame(kakaoId, game_id); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.