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
70import {
Controller,
Get,
Post,
Body,
Param,
Delete,
ParseIntPipe,
UseGuards,
Put,
} from '@nestjs/common';
import { CommentsService } from './comments.service';
import { CreateCommentDto } from './dto/create-comment.dto';
import { UpdateCommentDto } from './dto/update-comment.dto';
import { CurrentUser } from 'src/common/decorators/user.decorator';
import { ApiOperation, ApiTags } from '@nestjs/swagger';
import { JwtAuthGuard } from 'src/auth/jwt/jwt-auth.guard';
@ApiTags('COMMENTS')
@Controller('api/comments')
export class CommentsController {
constructor(private readonly commentsService: CommentsService) {}
@ApiOperation({ summary: 'λκΈ μμ±' })
@UseGuards(JwtAuthGuard)
@Post()
createComment(
@CurrentUser() user,
@Body() createCommentDto: CreateCommentDto,
) {
return this.commentsService.createComment(user.id, createCommentDto);
}
@ApiOperation({ summary: 'νΉμ κΈ λκΈ λͺ©λ‘ μ‘°ν' })
@Get(':postId')
async getCommentsByPostId(@Param('postId', ParseIntPipe) id: number) {
return await this.commentsService.getCommentsByPostId(id);
}
@ApiOperation({ summary: 'λκΈ μμ ' })
@UseGuards(JwtAuthGuard)
@Put(':id')
async updateComment(
@CurrentUser() user,
@Param('id', ParseIntPipe) id: number,
@Body() updateCommentDto: UpdateCommentDto,
) {
return await this.commentsService.updateComment(
id,
user.id,
user.role,
updateCommentDto,
);
}
@ApiOperation({ summary: 'λκΈ μμ ' })
@UseGuards(JwtAuthGuard)
@Delete(':id')
async deleteComment(
@CurrentUser() user,
@Param('id', ParseIntPipe) id: number,
) {
await this.commentsService.deleteComment(id, user.id, user.role);
return {
statusCode: 200,
message: 'λκΈ μμ μ±κ³΅',
};
}
}