完成剩余模块 Context 超时控制改造
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package withdrawal
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrDependencyUnavailable = errors.New("dependency unavailable")
|
||||
@@ -14,7 +17,7 @@ var (
|
||||
)
|
||||
|
||||
const (
|
||||
MinWithdrawalAmountCent = 1000 // 最低提现金额:10元 = 1000分
|
||||
MinWithdrawalAmountCent = 1000 // 最低提现金额:10元 = 1000分
|
||||
MaxWithdrawalAmountCent = 500000 // 单笔最高提现金额:5000元 = 500000分
|
||||
WithdrawalFeeRate = 0.0 // 手续费率(暂时0%)
|
||||
)
|
||||
@@ -28,7 +31,7 @@ func NewService(repo *Repository) *Service {
|
||||
}
|
||||
|
||||
// 用户端方法
|
||||
func (s *Service) Create(userID uint64, req CreateWithdrawalRequest) (*WithdrawalDTO, error) {
|
||||
func (s *Service) Create(ctx context.Context, userID uint64, req CreateWithdrawalRequest) (*WithdrawalDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
@@ -41,10 +44,10 @@ func (s *Service) Create(userID uint64, req CreateWithdrawalRequest) (*Withdrawa
|
||||
return nil, ErrMaxWithdrawalAmount
|
||||
}
|
||||
|
||||
return s.repo.Create(userID, req)
|
||||
return s.repo.Create(ctx, userID, req)
|
||||
}
|
||||
|
||||
func (s *Service) List(userID uint64, page, pageSize int) (*PaginatedResult, error) {
|
||||
func (s *Service) List(ctx context.Context, userID uint64, page, pageSize int) (*PaginatedResult, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
@@ -54,25 +57,25 @@ func (s *Service) List(userID uint64, page, pageSize int) (*PaginatedResult, err
|
||||
if pageSize < 1 || pageSize > 100 {
|
||||
pageSize = 20
|
||||
}
|
||||
return s.repo.List(userID, page, pageSize)
|
||||
return s.repo.List(ctx, userID, page, pageSize)
|
||||
}
|
||||
|
||||
func (s *Service) FindByID(userID, id uint64) (*WithdrawalDTO, error) {
|
||||
func (s *Service) FindByID(ctx context.Context, userID, id uint64) (*WithdrawalDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.FindByID(userID, id)
|
||||
return s.repo.FindByID(ctx, userID, id)
|
||||
}
|
||||
|
||||
func (s *Service) Cancel(userID, id uint64) error {
|
||||
func (s *Service) Cancel(ctx context.Context, userID, id uint64) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.Cancel(userID, id)
|
||||
return s.repo.Cancel(ctx, userID, id)
|
||||
}
|
||||
|
||||
// 管理员端方法
|
||||
func (s *Service) AdminList(query AdminListQuery) (*AdminPaginatedResult, error) {
|
||||
func (s *Service) AdminList(ctx context.Context, query AdminListQuery) (*AdminPaginatedResult, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
@@ -82,26 +85,26 @@ func (s *Service) AdminList(query AdminListQuery) (*AdminPaginatedResult, error)
|
||||
if query.Size < 1 || query.Size > 100 {
|
||||
query.Size = 20
|
||||
}
|
||||
return s.repo.AdminList(query)
|
||||
return s.repo.AdminList(ctx, query)
|
||||
}
|
||||
|
||||
func (s *Service) AdminFindByID(id uint64) (*WithdrawalDetailDTO, error) {
|
||||
func (s *Service) AdminFindByID(ctx context.Context, id uint64) (*WithdrawalDetailDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.AdminFindByID(id)
|
||||
return s.repo.AdminFindByID(ctx, id)
|
||||
}
|
||||
|
||||
func (s *Service) Review(adminID, id uint64, req ReviewWithdrawalRequest) (*WithdrawalDetailDTO, error) {
|
||||
func (s *Service) Review(ctx context.Context, adminID, id uint64, req ReviewWithdrawalRequest) (*WithdrawalDetailDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.Review(adminID, id, req)
|
||||
return s.repo.Review(ctx, adminID, id, req)
|
||||
}
|
||||
|
||||
func (s *Service) ConfirmPayment(adminID, id uint64, req ConfirmPaymentRequest) (*WithdrawalDetailDTO, error) {
|
||||
func (s *Service) ConfirmPayment(ctx context.Context, adminID, id uint64, req ConfirmPaymentRequest) (*WithdrawalDetailDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.ConfirmPayment(adminID, id, req)
|
||||
return s.repo.ConfirmPayment(ctx, adminID, id, req)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user