From 0010f216f3687a4ffc352f63f47c62c6515624de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=80=A7=E9=A9=8A?= Date: Fri, 2 May 2025 01:04:39 +0800 Subject: [PATCH] fix: comment public flag --- pkg/domain/usecase/comment.go | 1 + pkg/usecase/comment.go | 12 +++++++++--- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/domain/usecase/comment.go b/pkg/domain/usecase/comment.go index bb5946e..89d0e31 100644 --- a/pkg/domain/usecase/comment.go +++ b/pkg/domain/usecase/comment.go @@ -32,6 +32,7 @@ type CommentDocs struct { ParentCommentID string `json:"parent_comment_id"` // 父留言 id 沒有就空白 Message string `json:"message"` // 留言內容 Replies []*CommentDocs `json:"replies"` // 子留言 + IsVisitable bool `json:"is_visitable"` // 留言是否可見 UpdatedAt int64 `json:"updated_at"` // 更新時間 CreatedAt int64 `json:"created_at"` // 建立時間 } diff --git a/pkg/usecase/comment.go b/pkg/usecase/comment.go index 8639c4b..16b46c5 100644 --- a/pkg/usecase/comment.go +++ b/pkg/usecase/comment.go @@ -4,6 +4,7 @@ import ( "context" "encoding/base64" "fmt" + "google.golang.org/protobuf/proto" "code.30cm.net/digimon/app-cloudep-comment-server/pkg/domain" "code.30cm.net/digimon/app-cloudep-comment-server/pkg/domain/comment" @@ -89,6 +90,7 @@ func (use *CommentUseCase) GetCommentItem(ctx context.Context, id string) (*usec ReferenceID: byID.ReferenceID, ParentCommentID: byID.ParentCommentID, Message: byID.Message, + IsVisitable: byID.IsVisitable, UpdatedAt: byID.UpdatedAt, CreatedAt: byID.CreatedAt, }, nil @@ -140,6 +142,7 @@ func (use *CommentUseCase) ListComment(ctx context.Context, req usecase.ListComm ReferenceID: req.ReferenceID, IsVisitable: req.IsVisitable, }) + if err != nil { return nil, 0, errs.DatabaseErrorWithScopeL( code.CloudEPComment, @@ -173,6 +176,7 @@ func (use *CommentUseCase) ListComment(ctx context.Context, req usecase.ListComm Message: decodedMessage, UpdatedAt: item.UpdatedAt, CreatedAt: item.CreatedAt, + IsVisitable: item.IsVisitable, Replies: replyMap[item.ID.Hex()], }) } @@ -187,9 +191,10 @@ func (use *CommentUseCase) buildReplies(ctx context.Context, parentComments []*e for _, item := range parentComments { id := item.ID.Hex() subComments, _, err := use.Comment.ListComments(ctx, repository.ListCommentRequest{ - ParentID: &id, - PageSize: 20, - PageIndex: 1, // 可調整分頁大小 + ParentID: &id, + PageSize: 20, + PageIndex: 1, // 可調整分頁大小 + IsVisitable: proto.Bool(item.IsVisitable), }) if err != nil { continue @@ -207,6 +212,7 @@ func (use *CommentUseCase) buildReplies(ctx context.Context, parentComments []*e UID: sub.UID, ReferenceID: sub.ReferenceID, ParentCommentID: sub.ParentCommentID, + IsVisitable: sub.IsVisitable, Message: decodedMessage, UpdatedAt: sub.UpdatedAt, CreatedAt: sub.CreatedAt,