Skip to content

Commit

Permalink
Merge pull request #136 from modern-agile-team/feature/comment
Browse files Browse the repository at this point in the history
Refactor(2swo/Comment) Comment controller 커스텀데코레이터 적용
  • Loading branch information
2swo authored Nov 16, 2023
2 parents 7c366aa + 75b44a9 commit 1bbe6de
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/comments/controllers/comments.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@ import {
Controller,
Post,
Body,
Headers,
Query,
Get,
Patch,
Delete,
UseGuards,
} from '@nestjs/common';
import { Comment } from '../entities/comment.entity';
import { ApiTags } from '@nestjs/swagger';
import { CommentsService } from '../services/comments.services';
import { TokenService } from 'src/auth/services/token.service';
import { CreateCommentDto } from '../dto/create-comment-dto';
import { ApiAddComment } from '../swagger-decoratros/add-comment-decorators';
import { ApiGetAllComment } from '../swagger-decoratros/get-all-comment-decorators';
Expand All @@ -23,35 +22,36 @@ import { CreateReCommentDto } from '../dto/create-recomment-dto';
import { ReComment } from '../entities/recomment.entity';
import { ApiAddReComment } from '../swagger-decoratros/add-recomment-decorators';
import { ApiUpdateReComment } from '../swagger-decoratros/patch-recomment-decorator';
import { JwtAccessTokenGuard } from 'src/config/guards/jwt-access-token.guard';
import { GetUserId } from 'src/common/decorators/get-userId.decorator';

@Controller('comments')
@ApiTags('Comment API')
export class CommentsController {
constructor(
private readonly commentsService: CommentsService,
private readonly recommentsService: ReCommentsService,
private tokenService: TokenService,
) {}

@Post('')
@UseGuards(JwtAccessTokenGuard)
@ApiAddComment()
async createComment(
@Headers('access_token') accessToken: string,
@GetUserId() userId: number,
@Query('boardId') boardId: number,
@Body() createCommentDto: CreateCommentDto,
): Promise<Comment> {
const userId = await this.tokenService.decodeToken(accessToken);
return await this.commentsService.create(createCommentDto, userId, boardId);
}

@Post('/Re')
@UseGuards(JwtAccessTokenGuard)
@ApiAddReComment()
async createReComment(
@Headers('access_token') accessToken: string,
@GetUserId() userId: number,
@Query('commentId') commentId: number,
@Body() createReCommentDto: CreateReCommentDto,
): Promise<ReComment> {
const userId = await this.tokenService.decodeToken(accessToken);
return await this.recommentsService.create(
createReCommentDto,
userId,
Expand All @@ -60,12 +60,12 @@ export class CommentsController {
}

@Get('')
@UseGuards(JwtAccessTokenGuard)
@ApiGetAllComment()
async getComment(
@Headers('access_token') accessToken: string,
@GetUserId() userId: number,
@Query('boardId') boardId: number,
): Promise<commentResponseDTO[]> {
const userId = await this.tokenService.decodeToken(accessToken);
return this.commentsService.findAllComments(boardId, userId);
}

Expand All @@ -88,22 +88,22 @@ export class CommentsController {
}

@Delete('')
@UseGuards(JwtAccessTokenGuard)
@ApiDeleteComment()
async deleteComment(
@Query('commentId') commentId: number,
@Headers('access_token') accessToken: string,
@GetUserId() userId: number,
) {
const userId = await this.tokenService.decodeToken(accessToken);
await this.commentsService.deleteComment(commentId, userId);
}

@Delete('/Re')
@UseGuards(JwtAccessTokenGuard)
@ApiDeleteComment()
async deleteReComment(
@Query('reCommentId') reCommentId: number,
@Headers('access_token') accessToken: string,
@GetUserId() userId: number,
) {
const userId = await this.tokenService.decodeToken(accessToken);
await this.recommentsService.deleteReComment(reCommentId, userId);
}
}

0 comments on commit 1bbe6de

Please sign in to comment.