add order service logic
This commit is contained in:
parent
ea419a9943
commit
af6b700f9b
|
@ -5,8 +5,9 @@ import (
|
||||||
"app-cloudep-trade-service/internal/domain"
|
"app-cloudep-trade-service/internal/domain"
|
||||||
"app-cloudep-trade-service/internal/domain/usecase"
|
"app-cloudep-trade-service/internal/domain/usecase"
|
||||||
"app-cloudep-trade-service/internal/svc"
|
"app-cloudep-trade-service/internal/svc"
|
||||||
ers "code.30cm.net/digimon/library-go/errs"
|
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
ers "code.30cm.net/digimon/library-go/errs"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
"github.com/zeromicro/go-zero/core/logx"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -61,8 +62,8 @@ type createOrderReq struct { // 訂單ID
|
||||||
OrderNote *string `json:"order_note,omitempty" validate:"omitempty"`
|
OrderNote *string `json:"order_note,omitempty" validate:"omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gocyclo,gocognit
|
//nolint:gocyclo
|
||||||
func buildCreateOrderReq(in *trade.CreateOrderReq) (*createOrderReq, error) {
|
func buildCreateOrderReq(in *trade.CreateOrderReq) *createOrderReq {
|
||||||
createOrderReq := &createOrderReq{
|
createOrderReq := &createOrderReq{
|
||||||
BusinessID: in.BusinessId,
|
BusinessID: in.BusinessId,
|
||||||
OrderType: int8(in.OrderType),
|
OrderType: int8(in.OrderType),
|
||||||
|
@ -160,7 +161,7 @@ func buildCreateOrderReq(in *trade.CreateOrderReq) (*createOrderReq, error) {
|
||||||
createOrderReq.OrderNote = in.OrderNote
|
createOrderReq.OrderNote = in.OrderNote
|
||||||
}
|
}
|
||||||
|
|
||||||
return createOrderReq, nil
|
return createOrderReq
|
||||||
}
|
}
|
||||||
|
|
||||||
// toCreateOrderReq 將 createOrderReq 轉換為 CreateOrderReq
|
// toCreateOrderReq 將 createOrderReq 轉換為 CreateOrderReq
|
||||||
|
@ -206,12 +207,7 @@ func toCreateOrderUseCase(req *createOrderReq) usecase.CreateOrderReq {
|
||||||
|
|
||||||
// CreateOrder 建立訂單
|
// CreateOrder 建立訂單
|
||||||
func (l *CreateOrderLogic) CreateOrder(in *trade.CreateOrderReq) (*trade.OKResp, error) {
|
func (l *CreateOrderLogic) CreateOrder(in *trade.CreateOrderReq) (*trade.OKResp, error) {
|
||||||
|
req := buildCreateOrderReq(in)
|
||||||
req, err := buildCreateOrderReq(in)
|
|
||||||
if err != nil {
|
|
||||||
// 錯誤代碼 06-011-00
|
|
||||||
return nil, ers.InvalidFormat(err.Error())
|
|
||||||
}
|
|
||||||
|
|
||||||
// 驗證資料
|
// 驗證資料
|
||||||
if err := l.svcCtx.Validate.ValidateAll(req); err != nil {
|
if err := l.svcCtx.Validate.ValidateAll(req); err != nil {
|
||||||
|
@ -219,7 +215,7 @@ func (l *CreateOrderLogic) CreateOrder(in *trade.CreateOrderReq) (*trade.OKResp,
|
||||||
return nil, ers.InvalidFormat(err.Error())
|
return nil, ers.InvalidFormat(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
err = l.svcCtx.OrderUseCase.CreateOrder(l.ctx, toCreateOrderUseCase(req))
|
err := l.svcCtx.OrderUseCase.CreateOrder(l.ctx, toCreateOrderUseCase(req))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,28 +2,14 @@ package orderservicelogic
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/shopspring/decimal"
|
"github.com/shopspring/decimal"
|
||||||
"github.com/zeromicro/go-zero/core/logx"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func decimalPtrFromString(val string) *decimal.Decimal {
|
|
||||||
if val == "" {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
dec, err := decimal.NewFromString(val)
|
|
||||||
if err != nil {
|
|
||||||
logx.Errorf("Failed to convert string to decimal: %v", err)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return &dec
|
|
||||||
}
|
|
||||||
|
|
||||||
// getInt64Value 將 *int64 的值返回,如果為 nil 則返回 0
|
// getInt64Value 將 *int64 的值返回,如果為 nil 則返回 0
|
||||||
func getInt64Value(val *int64) int64 {
|
func getInt64Value(val *int64) int64 {
|
||||||
if val == nil {
|
if val == nil {
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
return *val
|
return *val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue