app-cloudep-trade-service/internal/logic/orderservice/delete_order_logic.go

52 lines
1.2 KiB
Go

package orderservicelogic
import (
"app-cloudep-trade-service/internal/domain/usecase"
ers "code.30cm.net/digimon/library-go/errs"
"context"
"app-cloudep-trade-service/gen_result/pb/trade"
"app-cloudep-trade-service/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
)
type DeleteOrderLogic struct {
ctx context.Context
svcCtx *svc.ServiceContext
logx.Logger
}
func NewDeleteOrderLogic(ctx context.Context, svcCtx *svc.ServiceContext) *DeleteOrderLogic {
return &DeleteOrderLogic{
ctx: ctx,
svcCtx: svcCtx,
Logger: logx.WithContext(ctx),
}
}
// DeleteOrderQuery 刪除訂單(軟刪除)
type DeleteOrderQuery struct {
BusinessID string `json:"business_id" validate:"required"`
}
// DeleteOrder 刪除訂單(軟刪除)
func (l *DeleteOrderLogic) DeleteOrder(in *trade.DeleteOrderReq) (*trade.OKResp, error) {
// 驗證資料
if err := l.svcCtx.Validate.ValidateAll(&DeleteOrderQuery{
BusinessID: in.GetBusinessId(),
}); err != nil {
// 錯誤代碼 06-011-00
return nil, ers.InvalidFormat(err.Error())
}
err := l.svcCtx.OrderUseCase.DeleteOrder(l.ctx, usecase.DeleteOrderQuery{
BusinessID: in.GetBusinessId(),
})
if err != nil {
return nil, err
}
return &trade.OKResp{}, nil
}