All files / comment comment.controller.ts

100% Statements 30/30
100% Branches 0/0
100% Functions 5/5
100% Lines 28/28

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 1494x                           4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x 4x           4x 15x                                         4x         1x                                             4x           1x 1x 1x                                           4x         1x                                           4x       1x      
import {
  Body,
  Controller,
  Get,
  HttpStatus,
  Param,
  Patch,
  Post,
  Put,
  Query,
  Req,
  UseGuards,
  UseInterceptors,
} from '@nestjs/common';
import { ApiBearerAuth, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from 'src/auth/guards/jwt-auth.guard';
import { CommentService } from 'src/comment/comment.service';
import { ApiCommentGetRequestQueryDto } from 'src/comment/dto/api-comment-get-request-query.dto';
import { ApiCommentGetResponseDto } from 'src/comment/dto/api-comment-get-response.dto';
import { ApiCommentPostRequestBodyDto } from 'src/comment/dto/api-community-post-request-body.dto';
import { ApiCommentPutRequestBodyDto } from 'src/comment/dto/api-community-put-request-body.dto';
import { ERROR } from 'src/commons/constants/error';
import { ApiExceptionResponse } from 'src/commons/decorators/api-exception-response.decorator';
import { ApiSuccessResponse } from 'src/commons/decorators/api-success-response.decorator';
import { CurrentUser } from 'src/commons/decorators/user.decorator';
import { UuidResponseDto } from 'src/commons/dtos/uuid-response.dto';
import { NotificationInterceptor } from 'src/commons/interceptors/notification.interceptor';
import { BadWordsPipe } from 'src/commons/pipe/badwords.pipe';
import { UserDto } from 'src/user/dto/user.dto';
 
@ApiTags('한줄평')
@Controller('/api/comment')
@UseGuards(JwtAuthGuard)
@ApiBearerAuth('access-token')
export class CommentController {
  constructor(private readonly commentService: CommentService) {}
 
  @Get('/:uuid')
  @ApiOperation({
    summary: '한줄평 조회',
    description: '한줄평 조회',
  })
  @ApiSuccessResponse(ApiCommentGetResponseDto, {
    description: '한줄평 조회 성공',
    status: HttpStatus.OK,
  })
  @ApiExceptionResponse([ERROR.NOT_EXIST_DATA], {
    description: '게시글이 존재하지 않을 경우',
    status: HttpStatus.NOT_FOUND,
  })
  @ApiParam({
    name: 'uuid',
    type: 'string',
    required: false,
    description: '커뮤니티 uuid',
  })
  async commentList(
    @Param('uuid') uuid: string,
    @Query() dto: ApiCommentGetRequestQueryDto,
    @CurrentUser() user: UserDto,
  ): Promise<ApiCommentGetResponseDto> {
    return this.commentService.commentList(uuid, dto, user);
  }
 
  @Post('/:uuid')
  @ApiOperation({
    summary: '한줄평 작성',
    description: '한줄평 작성',
  })
  @ApiSuccessResponse(UuidResponseDto, {
    description: '한줄평 작성 성공',
    status: HttpStatus.CREATED,
  })
  @ApiExceptionResponse([ERROR.NOT_EXIST_DATA], {
    description: '게시글이 존재하지 않을 경우',
    status: HttpStatus.NOT_FOUND,
  })
  @ApiParam({
    name: 'uuid',
    type: 'string',
    required: false,
    description: '커뮤니티 uuid',
  })
  @UseInterceptors(NotificationInterceptor)
  async commentPost(
    @Param('uuid') uuid: string,
    @CurrentUser() user: UserDto,
    @Body(BadWordsPipe) dto: ApiCommentPostRequestBodyDto,
    @Req() req,
  ): Promise<UuidResponseDto> {
    const res = await this.commentService.commentPost(uuid, user, dto);
    req.notification = res.notification;
    return res.data;
  }
 
  @Put('/:uuid')
  @ApiOperation({
    summary: '한줄평 수정',
    description: '한줄평 수정',
  })
  @ApiSuccessResponse(UuidResponseDto, {
    description: '한줄평 수정 성공',
    status: HttpStatus.OK,
  })
  @ApiExceptionResponse([ERROR.NOT_EXIST_DATA], {
    description: '댓글 uuid가 존재하지 않거나 댓글 작성자와 유저가 다른 경우',
    status: HttpStatus.NOT_FOUND,
  })
  @ApiParam({
    name: 'uuid',
    type: 'string',
    required: false,
    description: '댓글 uuid',
  })
  async commentUpdate(
    @CurrentUser() user: UserDto,
    @Body(BadWordsPipe) dto: ApiCommentPutRequestBodyDto,
    @Param('uuid') uuid: string,
  ): Promise<UuidResponseDto> {
    return this.commentService.commentUpdate(user, dto, uuid);
  }
 
  @Patch('/:uuid')
  @ApiOperation({
    summary: '한줄평 삭제',
    description: '한줄평 삭제',
  })
  @ApiSuccessResponse(UuidResponseDto, {
    description: '한줄평 삭제 완료',
    status: HttpStatus.NO_CONTENT,
  })
  @ApiExceptionResponse([ERROR.NOT_EXIST_DATA], {
    description: '댓글 uuid가 존재하지 않거나 댓글 작성자와 유저가 다른 경우',
    status: HttpStatus.NOT_FOUND,
  })
  @ApiParam({
    name: 'uuid',
    type: 'string',
    required: false,
    description: '댓글 uuid',
  })
  async commentDelete(
    @CurrentUser() user: UserDto,
    @Param('uuid') uuid: string,
  ): Promise<UuidResponseDto> {
    return this.commentService.commentDelete(user, uuid);
  }
}