feat: add wallet transaction

This commit is contained in:
王性驊 2025-05-01 23:06:52 +08:00
parent 35b850d53d
commit 283d196f6b
3 changed files with 28 additions and 15 deletions

View File

@ -12,6 +12,7 @@ type CommentRepository interface {
DeleteCommentByID(ctx context.Context, id string) error // 根據 ID 刪除留言 // 刪除某留言的所有子留言
UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error // 更新留言內容
ListComments(ctx context.Context, req ListCommentRequest) ([]*entity.Comments, int64, error) // 分頁列出留言
GetCommentByID(ctx context.Context, id string) (*entity.Comments, error)
}
type ListCommentRequest struct {

View File

@ -72,6 +72,22 @@ func (repo *CommentRepository) DeleteCommentByID(ctx context.Context, id string)
return err
}
func (repo *CommentRepository) GetCommentByID(ctx context.Context, id string) (*entity.Comments, error) {
oid, err := primitive.ObjectIDFromHex(id)
if err != nil {
return nil, ErrInvalidObjectID
}
result := entity.Comments{}
rk := domain.GetCommentRedisKey(id)
err = repo.DB.FindOne(ctx, rk, &result, bson.M{"_id": oid})
if err != nil {
return nil, err
}
return &result, nil
}
func (repo *CommentRepository) UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error {
// 驗證 ObjectID 是否有效
oid, err := primitive.ObjectIDFromHex(id)

View File

@ -65,11 +65,7 @@ func (use *CommentUseCase) CreateCommentItem(ctx context.Context, info usecase.C
}
func (use *CommentUseCase) GetCommentItem(ctx context.Context, id string) (*usecase.CommentDocs, error) {
item, _, err := use.Comment.ListComments(ctx, repository.ListCommentRequest{
ReferenceID: &id,
PageIndex: 1,
PageSize: 20,
})
byID, err := use.Comment.GetCommentByID(ctx, id)
if err != nil {
return nil, errs.DatabaseErrorWithScopeL(
code.CloudEPComment,
@ -80,21 +76,21 @@ func (use *CommentUseCase) GetCommentItem(ctx context.Context, id string) (*usec
{Key: "func", Value: "Comment.ListComments"},
{Key: "err", Value: err.Error()},
},
"failed to get comment").Wrap(err)
"failed to get byID").Wrap(err)
}
decodeB64Content, _ := base64.StdEncoding.DecodeString(item[0].Message)
decodeB64Content, _ := base64.StdEncoding.DecodeString(byID.Message)
snappyContent, _ := snappy.Decode(nil, decodeB64Content)
item[0].Message = string(snappyContent)
byID.Message = string(snappyContent)
return &usecase.CommentDocs{
ID: item[0].ID.Hex(),
UID: item[0].UID,
ReferenceID: item[0].ReferenceID,
ParentCommentID: item[0].ParentCommentID,
Message: item[0].Message,
UpdatedAt: item[0].UpdatedAt,
CreatedAt: item[0].CreatedAt,
ID: byID.ID.Hex(),
UID: byID.UID,
ReferenceID: byID.ReferenceID,
ParentCommentID: byID.ParentCommentID,
Message: byID.Message,
UpdatedAt: byID.UpdatedAt,
CreatedAt: byID.CreatedAt,
}, nil
}