Skip to content

Commit

Permalink
Refactor(#117) Board-like controller 커스텀데코레이터 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
2swo committed Nov 13, 2023
1 parent 7b68003 commit 1e4740a
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions src/boards/controllers/boards-like.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import {
UsePipes,
ValidationPipe,
Query,
Headers,
UseGuards,
} from '@nestjs/common';
import { BoardsLikeService } from '../services/boards-like.service';
import { ApiTags } from '@nestjs/swagger';
import { ApiAddBoardLike } from '../swagger-decorators/add-board-like.decorator';
import { ApiGetBoardLikeCount } from '../swagger-decorators/get-board-like-count.decorator';
import { ApiDeleteBoardLike } from '../swagger-decorators/delete-board-like.decorator';
import { TokenService } from 'src/auth/services/token.service';
import { GetUserId } from 'src/common/decorators/get-userId.decorator';
import { JwtAccessTokenGuard } from 'src/config/guards/jwt-access-token.guard';

@ApiTags('BOARDS-LIKE')
@UsePipes(ValidationPipe)
Expand All @@ -28,23 +30,22 @@ export class BoardsLikeController {

@ApiAddBoardLike()
@Post('like/:boardId')
@UseGuards(JwtAccessTokenGuard)
async addBoardLike(
@Headers('access_token') accessToken: string,
@GetUserId() userId: number,
@Param('boardId', ParseIntPipe) boardId: number,
) {
const userId = await this.tokenService.decodeToken(accessToken);
return this.boardsLikeService.addBoardLike(boardId, userId);
}

@ApiGetBoardLikeCount()
@Get('like')
@UseGuards(JwtAccessTokenGuard)
async getBoardsLike(
@Headers('access_token') accessToken: string,
@GetUserId() userId: number,
@Query('boardId', ParseIntPipe) boardId: number,
) {
try {
const userId = await this.tokenService.decodeToken(accessToken);

return this.boardsLikeService.getBoardLikesAndIsLike(boardId, userId);
} catch (error) {
if (
Expand All @@ -65,12 +66,12 @@ export class BoardsLikeController {

@ApiDeleteBoardLike()
@Delete('like/:boardId')
@UseGuards(JwtAccessTokenGuard)
async deleteBoardLike(
@Headers('access_token') accessToken: string,
@GetUserId() userId: number,
@Param('boardId', ParseIntPipe)
boardId: number,
) {
const userId = await this.tokenService.decodeToken(accessToken);
return this.boardsLikeService.deleteBoardLike(boardId, userId);
}
}

0 comments on commit 1e4740a

Please sign in to comment.