新增文章阅读数功能,包括在控制器和服务中添加增加阅读数的方法,并更新相关路由以支持该功能。

This commit is contained in:
richarjiang
2025-08-14 16:11:22 +08:00
parent b4dfdcfe70
commit 96a1190f74
3 changed files with 173 additions and 172 deletions

View File

@@ -57,6 +57,14 @@ export class ArticlesService {
await article.save();
return { code: ResponseCode.SUCCESS, message: 'success', data: article.toJSON() as ArticleVo };
}
async increaseReadCount(id: string) {
const article = await this.articleModel.findByPk(id);
if (!article) throw new NotFoundException('文章不存在');
article.readCount += 1;
await article.save();
return { code: ResponseCode.SUCCESS, message: 'success', data: article.toJSON() as ArticleVo };
}
}