Compare commits

...

2 Commits

Author SHA1 Message Date
王性驊 0dcd5fcf11 fix: comment public flag 2025-05-05 20:54:52 +08:00
王性驊 0010f216f3 fix: comment public flag 2025-05-02 01:04:39 +08:00
3 changed files with 16 additions and 4 deletions

View File

@ -32,6 +32,7 @@ type CommentDocs struct {
ParentCommentID string `json:"parent_comment_id"` // 父留言 id 沒有就空白 ParentCommentID string `json:"parent_comment_id"` // 父留言 id 沒有就空白
Message string `json:"message"` // 留言內容 Message string `json:"message"` // 留言內容
Replies []*CommentDocs `json:"replies"` // 子留言 Replies []*CommentDocs `json:"replies"` // 子留言
IsVisitable bool `json:"is_visitable"` // 留言是否可見
UpdatedAt int64 `json:"updated_at"` // 更新時間 UpdatedAt int64 `json:"updated_at"` // 更新時間
CreatedAt int64 `json:"created_at"` // 建立時間 CreatedAt int64 `json:"created_at"` // 建立時間
} }

View File

@ -25,6 +25,8 @@ type MockCommentRepository struct {
isgomock struct{} isgomock struct{}
} }
// MockCommentRepositoryMockRecorder is the mock recorder for MockCommentRepository. // MockCommentRepositoryMockRecorder is the mock recorder for MockCommentRepository.
type MockCommentRepositoryMockRecorder struct { type MockCommentRepositoryMockRecorder struct {
mock *MockCommentRepository mock *MockCommentRepository

View File

@ -4,6 +4,7 @@ import (
"context" "context"
"encoding/base64" "encoding/base64"
"fmt" "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"
"code.30cm.net/digimon/app-cloudep-comment-server/pkg/domain/comment" "code.30cm.net/digimon/app-cloudep-comment-server/pkg/domain/comment"
@ -89,13 +90,17 @@ func (use *CommentUseCase) GetCommentItem(ctx context.Context, id string) (*usec
ReferenceID: byID.ReferenceID, ReferenceID: byID.ReferenceID,
ParentCommentID: byID.ParentCommentID, ParentCommentID: byID.ParentCommentID,
Message: byID.Message, Message: byID.Message,
IsVisitable: byID.IsVisitable,
UpdatedAt: byID.UpdatedAt, UpdatedAt: byID.UpdatedAt,
CreatedAt: byID.CreatedAt, CreatedAt: byID.CreatedAt,
}, nil }, nil
} }
func (use *CommentUseCase) UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error { func (use *CommentUseCase) UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error {
err := use.Comment.UpdateCommentMessage(ctx, id, message, isVisitable) snappyContent := snappy.Encode(nil, []byte(message))
msg := base64.StdEncoding.EncodeToString(snappyContent)
err := use.Comment.UpdateCommentMessage(ctx, id, msg, isVisitable)
if err != nil { if err != nil {
return errs.DatabaseErrorWithScopeL( return errs.DatabaseErrorWithScopeL(
code.CloudEPComment, code.CloudEPComment,
@ -140,6 +145,7 @@ func (use *CommentUseCase) ListComment(ctx context.Context, req usecase.ListComm
ReferenceID: req.ReferenceID, ReferenceID: req.ReferenceID,
IsVisitable: req.IsVisitable, IsVisitable: req.IsVisitable,
}) })
if err != nil { if err != nil {
return nil, 0, errs.DatabaseErrorWithScopeL( return nil, 0, errs.DatabaseErrorWithScopeL(
code.CloudEPComment, code.CloudEPComment,
@ -173,6 +179,7 @@ func (use *CommentUseCase) ListComment(ctx context.Context, req usecase.ListComm
Message: decodedMessage, Message: decodedMessage,
UpdatedAt: item.UpdatedAt, UpdatedAt: item.UpdatedAt,
CreatedAt: item.CreatedAt, CreatedAt: item.CreatedAt,
IsVisitable: item.IsVisitable,
Replies: replyMap[item.ID.Hex()], Replies: replyMap[item.ID.Hex()],
}) })
} }
@ -187,9 +194,10 @@ func (use *CommentUseCase) buildReplies(ctx context.Context, parentComments []*e
for _, item := range parentComments { for _, item := range parentComments {
id := item.ID.Hex() id := item.ID.Hex()
subComments, _, err := use.Comment.ListComments(ctx, repository.ListCommentRequest{ subComments, _, err := use.Comment.ListComments(ctx, repository.ListCommentRequest{
ParentID: &id, ParentID: &id,
PageSize: 20, PageSize: 20,
PageIndex: 1, // 可調整分頁大小 PageIndex: 1, // 可調整分頁大小
IsVisitable: proto.Bool(item.IsVisitable),
}) })
if err != nil { if err != nil {
continue continue
@ -207,6 +215,7 @@ func (use *CommentUseCase) buildReplies(ctx context.Context, parentComments []*e
UID: sub.UID, UID: sub.UID,
ReferenceID: sub.ReferenceID, ReferenceID: sub.ReferenceID,
ParentCommentID: sub.ParentCommentID, ParentCommentID: sub.ParentCommentID,
IsVisitable: sub.IsVisitable,
Message: decodedMessage, Message: decodedMessage,
UpdatedAt: sub.UpdatedAt, UpdatedAt: sub.UpdatedAt,
CreatedAt: sub.CreatedAt, CreatedAt: sub.CreatedAt,