From aeab4959e5ed5a4326a09e9a30b08ed43a7d9466 Mon Sep 17 00:00:00 2001 From: wibus-wee <1596355173@qq.com> Date: Sun, 16 Apr 2023 21:43:30 +0800 Subject: [PATCH] fix(friends-service): wrong comment details api --- .../src/comments-service.controller.ts | 5 +++++ .../comments-service/src/comments-service.service.ts | 4 ++++ .../core/src/modules/comments/comments.controller.ts | 12 +++++++++++- shared/constants/event.constant.ts | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/apps/comments-service/src/comments-service.controller.ts b/apps/comments-service/src/comments-service.controller.ts index b0db28729..95ad14fa1 100644 --- a/apps/comments-service/src/comments-service.controller.ts +++ b/apps/comments-service/src/comments-service.controller.ts @@ -45,6 +45,11 @@ export class CommentsController { return await this.commentsService.getCommentsByPid(input.pid, input.master); } + @MessagePattern({ cmd: CommentsEvents.CommentGetById }) + async getCommentById(id: string) { + return await this.commentsService.getCommentById(id); + } + @MessagePattern({ cmd: CommentsEvents.CommentCreate }) async createComment(input: { data: CommentsModel; master: boolean }) { if (!input.master) { diff --git a/apps/comments-service/src/comments-service.service.ts b/apps/comments-service/src/comments-service.service.ts index bbdb855bf..279cea483 100644 --- a/apps/comments-service/src/comments-service.service.ts +++ b/apps/comments-service/src/comments-service.service.ts @@ -69,6 +69,10 @@ export class CommentsService { }; } + async getCommentById(id: string) { + return await this.CommentsModel.findById(id); + } + async createComment(data: CommentsModel, isMaster: boolean) { if (isMaster) { data.status = CommentStatus.Approved; // 默认审核通过主人的评论 diff --git a/apps/core/src/modules/comments/comments.controller.ts b/apps/core/src/modules/comments/comments.controller.ts index 50e4e8c12..e2748c89d 100644 --- a/apps/core/src/modules/comments/comments.controller.ts +++ b/apps/core/src/modules/comments/comments.controller.ts @@ -50,7 +50,17 @@ export class CommentsController { ); } - @Get('/:id') + @Get("/:id") + @ApiOperation({ summary: "根据 ID 获取评论" }) + async getCommentById(@Param("id") id: string) { + return transportReqToMicroservice( + this.comments, + CommentsEvents.CommentGetById, + id + ); + } + + @Get('/post/:id') @ApiOperation({ summary: '根据 PID 获取评论列表' }) async getCommentsByPid( @Param('id') pid: string, diff --git a/shared/constants/event.constant.ts b/shared/constants/event.constant.ts index 5fc884490..15a670ae6 100644 --- a/shared/constants/event.constant.ts +++ b/shared/constants/event.constant.ts @@ -57,6 +57,7 @@ export enum PageEvents { export enum CommentsEvents { CommentsGetAll = 'sudo.comments.get.all', CommentsGetList = 'comments.get.list', + CommentGetById = 'comment.get.with.id', CommentsGetWithPostId = 'comments.get.with.postid', CommentsDeleteWithPostId = 'comments.delete.with.postid',