feat: add wallet transaction
This commit is contained in:
parent
35b850d53d
commit
283d196f6b
|
@ -12,6 +12,7 @@ type CommentRepository interface {
|
||||||
DeleteCommentByID(ctx context.Context, id string) error // 根據 ID 刪除留言 // 刪除某留言的所有子留言
|
DeleteCommentByID(ctx context.Context, id string) error // 根據 ID 刪除留言 // 刪除某留言的所有子留言
|
||||||
UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error // 更新留言內容
|
UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error // 更新留言內容
|
||||||
ListComments(ctx context.Context, req ListCommentRequest) ([]*entity.Comments, int64, error) // 分頁列出留言
|
ListComments(ctx context.Context, req ListCommentRequest) ([]*entity.Comments, int64, error) // 分頁列出留言
|
||||||
|
GetCommentByID(ctx context.Context, id string) (*entity.Comments, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type ListCommentRequest struct {
|
type ListCommentRequest struct {
|
||||||
|
|
|
@ -72,6 +72,22 @@ func (repo *CommentRepository) DeleteCommentByID(ctx context.Context, id string)
|
||||||
return err
|
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 {
|
func (repo *CommentRepository) UpdateCommentMessage(ctx context.Context, id string, message string, isVisitable bool) error {
|
||||||
// 驗證 ObjectID 是否有效
|
// 驗證 ObjectID 是否有效
|
||||||
oid, err := primitive.ObjectIDFromHex(id)
|
oid, err := primitive.ObjectIDFromHex(id)
|
||||||
|
|
|
@ -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) {
|
func (use *CommentUseCase) GetCommentItem(ctx context.Context, id string) (*usecase.CommentDocs, error) {
|
||||||
item, _, err := use.Comment.ListComments(ctx, repository.ListCommentRequest{
|
byID, err := use.Comment.GetCommentByID(ctx, id)
|
||||||
ReferenceID: &id,
|
|
||||||
PageIndex: 1,
|
|
||||||
PageSize: 20,
|
|
||||||
})
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errs.DatabaseErrorWithScopeL(
|
return nil, errs.DatabaseErrorWithScopeL(
|
||||||
code.CloudEPComment,
|
code.CloudEPComment,
|
||||||
|
@ -80,21 +76,21 @@ func (use *CommentUseCase) GetCommentItem(ctx context.Context, id string) (*usec
|
||||||
{Key: "func", Value: "Comment.ListComments"},
|
{Key: "func", Value: "Comment.ListComments"},
|
||||||
{Key: "err", Value: err.Error()},
|
{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)
|
snappyContent, _ := snappy.Decode(nil, decodeB64Content)
|
||||||
item[0].Message = string(snappyContent)
|
byID.Message = string(snappyContent)
|
||||||
|
|
||||||
return &usecase.CommentDocs{
|
return &usecase.CommentDocs{
|
||||||
ID: item[0].ID.Hex(),
|
ID: byID.ID.Hex(),
|
||||||
UID: item[0].UID,
|
UID: byID.UID,
|
||||||
ReferenceID: item[0].ReferenceID,
|
ReferenceID: byID.ReferenceID,
|
||||||
ParentCommentID: item[0].ParentCommentID,
|
ParentCommentID: byID.ParentCommentID,
|
||||||
Message: item[0].Message,
|
Message: byID.Message,
|
||||||
UpdatedAt: item[0].UpdatedAt,
|
UpdatedAt: byID.UpdatedAt,
|
||||||
CreatedAt: item[0].CreatedAt,
|
CreatedAt: byID.CreatedAt,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue