继续补齐核心模块 Context 超时控制
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
package order
|
||||
|
||||
import "errors"
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
)
|
||||
|
||||
var (
|
||||
ErrDependencyUnavailable = errors.New("dependency unavailable")
|
||||
@@ -32,179 +35,179 @@ func NewService(repo *Repository) *Service {
|
||||
return &Service{repo: repo}
|
||||
}
|
||||
|
||||
func (s *Service) Create(userID uint64, req CreateRequest) (*OrderDTO, error) {
|
||||
func (s *Service) Create(ctx context.Context, userID uint64, req CreateRequest) (*OrderDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
if req.ListingID == 0 {
|
||||
return nil, ErrInvalidRentHours
|
||||
}
|
||||
return s.repo.Create(userID, req)
|
||||
return s.repo.Create(ctx, userID, req)
|
||||
}
|
||||
|
||||
func (s *Service) Cancel(userID uint64, orderID uint64) error {
|
||||
func (s *Service) Cancel(ctx context.Context, userID uint64, orderID uint64) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.Cancel(userID, orderID)
|
||||
return s.repo.Cancel(ctx, userID, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) Pay(userID uint64, orderID uint64) error {
|
||||
func (s *Service) Pay(ctx context.Context, userID uint64, orderID uint64) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 {
|
||||
return ErrOrderCannotPay
|
||||
}
|
||||
return s.repo.Pay(userID, orderID)
|
||||
return s.repo.Pay(ctx, userID, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) SubmitHandoff(userID uint64, orderID uint64, req SubmitHandoffRequest) (*HandoffRecordDTO, error) {
|
||||
func (s *Service) SubmitHandoff(ctx context.Context, userID uint64, orderID uint64, req SubmitHandoffRequest) (*HandoffRecordDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 || req.Content == "" {
|
||||
return nil, ErrOrderCannotHandoff
|
||||
}
|
||||
return s.repo.SubmitHandoff(userID, orderID, req)
|
||||
return s.repo.SubmitHandoff(ctx, userID, orderID, req)
|
||||
}
|
||||
|
||||
func (s *Service) ConfirmReceive(userID uint64, orderID uint64) error {
|
||||
func (s *Service) ConfirmReceive(ctx context.Context, userID uint64, orderID uint64) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.ConfirmReceive(userID, orderID)
|
||||
return s.repo.ConfirmReceive(ctx, userID, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) HandoffRecords(userID uint64, orderID uint64) ([]HandoffRecordDTO, error) {
|
||||
func (s *Service) HandoffRecords(ctx context.Context, userID uint64, orderID uint64) ([]HandoffRecordDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.HandoffRecords(userID, orderID)
|
||||
return s.repo.HandoffRecords(ctx, userID, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) SubmitReturn(userID uint64, orderID uint64, req SubmitReturnRequest) (*HandoffRecordDTO, error) {
|
||||
func (s *Service) SubmitReturn(ctx context.Context, userID uint64, orderID uint64, req SubmitReturnRequest) (*HandoffRecordDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 || req.Content == "" {
|
||||
return nil, ErrOrderCannotReturn
|
||||
}
|
||||
return s.repo.SubmitReturn(userID, orderID, req)
|
||||
return s.repo.SubmitReturn(ctx, userID, orderID, req)
|
||||
}
|
||||
|
||||
func (s *Service) SubmitCheckout(userID uint64, orderID uint64, req SubmitCheckoutRequest) (*HandoffRecordDTO, error) {
|
||||
func (s *Service) SubmitCheckout(ctx context.Context, userID uint64, orderID uint64, req SubmitCheckoutRequest) (*HandoffRecordDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 || req.Content == "" {
|
||||
return nil, ErrCheckoutCannotSubmit
|
||||
}
|
||||
return s.repo.SubmitCheckout(userID, orderID, req)
|
||||
return s.repo.SubmitCheckout(ctx, userID, orderID, req)
|
||||
}
|
||||
|
||||
func (s *Service) ConfirmReturn(userID uint64, orderID uint64) error {
|
||||
func (s *Service) ConfirmReturn(ctx context.Context, userID uint64, orderID uint64) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.ConfirmReturn(userID, orderID)
|
||||
return s.repo.ConfirmReturn(ctx, userID, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) ConfirmCheckout(userID uint64, orderID uint64) error {
|
||||
func (s *Service) ConfirmCheckout(ctx context.Context, userID uint64, orderID uint64) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.ConfirmCheckout(userID, orderID)
|
||||
return s.repo.ConfirmCheckout(ctx, userID, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) CounterCheckout(userID uint64, orderID uint64, req CounterCheckoutRequest) (*CheckoutDTO, error) {
|
||||
func (s *Service) CounterCheckout(ctx context.Context, userID uint64, orderID uint64, req CounterCheckoutRequest) (*CheckoutDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return nil, ErrCheckoutCannotCounter
|
||||
}
|
||||
return s.repo.CounterCheckout(userID, orderID, req)
|
||||
return s.repo.CounterCheckout(ctx, userID, orderID, req)
|
||||
}
|
||||
|
||||
func (s *Service) AcceptCheckout(userID uint64, orderID uint64) error {
|
||||
func (s *Service) AcceptCheckout(ctx context.Context, userID uint64, orderID uint64) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.AcceptCheckout(userID, orderID)
|
||||
return s.repo.AcceptCheckout(ctx, userID, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) ListForUser(userID uint64) ([]OrderDTO, error) {
|
||||
func (s *Service) ListForUser(ctx context.Context, userID uint64) ([]OrderDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.ListForUser(userID)
|
||||
return s.repo.ListForUser(ctx, userID)
|
||||
}
|
||||
|
||||
func (s *Service) ListAdmin(page, pageSize int) (*PaginatedResult, error) {
|
||||
func (s *Service) ListAdmin(ctx context.Context, page, pageSize int) (*PaginatedResult, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.ListAdmin(page, pageSize)
|
||||
return s.repo.ListAdmin(ctx, page, pageSize)
|
||||
}
|
||||
|
||||
func (s *Service) FindAdmin(orderID uint64) (*OrderDTO, error) {
|
||||
func (s *Service) FindAdmin(ctx context.Context, orderID uint64) (*OrderDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.FindAdmin(orderID)
|
||||
return s.repo.FindAdmin(ctx, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) HandoffRecordsAdmin(orderID uint64) ([]HandoffRecordDTO, error) {
|
||||
func (s *Service) HandoffRecordsAdmin(ctx context.Context, orderID uint64) ([]HandoffRecordDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.HandoffRecordsAdmin(orderID)
|
||||
return s.repo.HandoffRecordsAdmin(ctx, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) AdminClose(adminID uint64, orderID uint64, req AdminActionRequest, meta AuditMeta) error {
|
||||
func (s *Service) AdminClose(ctx context.Context, adminID uint64, orderID uint64, req AdminActionRequest, meta AuditMeta) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrOrderCannotComplete
|
||||
}
|
||||
return s.repo.AdminClose(adminID, orderID, req, meta)
|
||||
return s.repo.AdminClose(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
func (s *Service) AdminMarkAbnormal(adminID uint64, orderID uint64, req AdminActionRequest, meta AuditMeta) error {
|
||||
func (s *Service) AdminMarkAbnormal(ctx context.Context, adminID uint64, orderID uint64, req AdminActionRequest, meta AuditMeta) error {
|
||||
if s.repo == nil {
|
||||
return ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 || req.Reason == "" {
|
||||
return ErrOrderCannotComplete
|
||||
}
|
||||
return s.repo.AdminMarkAbnormal(adminID, orderID, req, meta)
|
||||
return s.repo.AdminMarkAbnormal(ctx, adminID, orderID, req, meta)
|
||||
}
|
||||
|
||||
func (s *Service) AdminRefund(orderID uint64) (*RefundStatusDTO, error) {
|
||||
func (s *Service) AdminRefund(ctx context.Context, orderID uint64) (*RefundStatusDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 {
|
||||
return nil, ErrOrderCannotComplete
|
||||
}
|
||||
return s.repo.AdminRefund(orderID)
|
||||
return s.repo.AdminRefund(ctx, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) AdminRefundStatus(orderID uint64) (*RefundStatusDTO, error) {
|
||||
func (s *Service) AdminRefundStatus(ctx context.Context, orderID uint64) (*RefundStatusDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
if orderID == 0 {
|
||||
return nil, ErrOrderCannotComplete
|
||||
}
|
||||
return s.repo.AdminRefundStatus(orderID)
|
||||
return s.repo.AdminRefundStatus(ctx, orderID)
|
||||
}
|
||||
|
||||
func (s *Service) FindForUser(userID uint64, orderID uint64) (*OrderDTO, error) {
|
||||
func (s *Service) FindForUser(ctx context.Context, userID uint64, orderID uint64) (*OrderDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
return s.repo.FindForUser(userID, orderID)
|
||||
return s.repo.FindForUser(ctx, userID, orderID)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user