初步完成评论
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { BadRequestException, Controller, Get, Param, ParseUUIDPipe } from '@nestjs/common';
|
||||
import { BadRequestException, Body, Controller, Get, Param, ParseUUIDPipe, Post } from '@nestjs/common';
|
||||
import { BlogService } from './blog.service';
|
||||
|
||||
@Controller('blog')
|
||||
@@ -31,4 +31,31 @@ export class BlogController {
|
||||
content: blogContent,
|
||||
};
|
||||
}
|
||||
|
||||
@Get(':id/comments')
|
||||
async getBlogComments(
|
||||
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
||||
) {
|
||||
const blog = await this.blogService.findById(id);
|
||||
if (!blog) throw new BadRequestException('文章不存在');
|
||||
|
||||
return await this.blogService.getComments(id);
|
||||
}
|
||||
|
||||
// TODO:鉴权,该接口允许匿名评论,但仍需验证userId合法性
|
||||
@Post(':id/comment')
|
||||
async createBlogComment(
|
||||
@Param('id', new ParseUUIDPipe({ version: '4' })) id: string,
|
||||
@Body() commentData: { content: string },
|
||||
) {
|
||||
const blog = await this.blogService.findById(id);
|
||||
if (!blog) throw new BadRequestException('文章不存在');
|
||||
|
||||
const comment = {
|
||||
...commentData,
|
||||
blogId: id,
|
||||
};
|
||||
|
||||
return await this.blogService.createComment(comment);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user