|
1 |
| -import { Controller, Post, Get, Patch } from '@nestjs/common'; |
| 1 | +import { |
| 2 | + Controller, |
| 3 | + Post, |
| 4 | + Get, |
| 5 | + Patch, |
| 6 | + Body, |
| 7 | + Req, |
| 8 | + Query, |
| 9 | + UseGuards, |
| 10 | +} from '@nestjs/common'; |
2 | 11 | import { PostCommentService } from './post-comment.service';
|
3 | 12 | import {
|
4 | 13 | CreatePostCommentSwagger,
|
5 | 14 | DeletePostCommentSwagger,
|
6 | 15 | GetPostCommentsSwagger,
|
7 | 16 | } from './post-comment.swagger';
|
| 17 | +import { CreateCommentDto } from './dtos/create-comment.dto'; |
| 18 | +import { Request } from 'express'; |
| 19 | +import { BaseResponse } from 'src/common/response/dto'; |
| 20 | +import { PostService } from 'src/post/post.service'; |
| 21 | +import { AuthGuard } from 'src/auth/guards/jwt.auth.guard'; |
8 | 22 | import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
9 | 23 |
|
10 | 24 | @ApiBearerAuth()
|
11 | 25 | @Controller('post-comment')
|
| 26 | +@UseGuards(AuthGuard) |
12 | 27 | @ApiTags('[서비스] 게시글 댓글')
|
13 | 28 | export class PostCommentController {
|
14 |
| - constructor(private readonly postCommentService: PostCommentService) {} |
| 29 | + constructor( |
| 30 | + private readonly postCommentService: PostCommentService, |
| 31 | + private readonly postService: PostService, |
| 32 | + ) {} |
15 | 33 |
|
16 | 34 | @Post()
|
17 | 35 | @CreatePostCommentSwagger('게시글 댓글 생성 API')
|
18 |
| - createPostComment() { |
19 |
| - // return this.userService.getHello(); |
| 36 | + async createPostComment( |
| 37 | + @Query('postId') postId: number, |
| 38 | + @Body() createCommentDto: CreateCommentDto, |
| 39 | + @Req() req: Request, |
| 40 | + ): Promise<BaseResponse<any>> { |
| 41 | + const currentUserId = req.user.userId; |
| 42 | + |
| 43 | + await this.postService.validatePost(postId); |
| 44 | + |
| 45 | + const postComment = await this.postCommentService.createPostComment( |
| 46 | + postId, |
| 47 | + currentUserId, |
| 48 | + createCommentDto, |
| 49 | + ); |
| 50 | + |
| 51 | + return new BaseResponse(true, '댓글 작성 성공', postComment); |
20 | 52 | }
|
21 | 53 |
|
22 | 54 | @Get()
|
|
0 commit comments