From ac1ec030dbe32db81f8ef8dba2e7fdf398e008e0 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 2 Nov 2022 17:27:10 +0700 Subject: [PATCH] define nats func - get supplier order cash and supplier withdraw cash --- client/order.go | 21 +++++++++++++++++++++ client/withdraw.go | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 client/withdraw.go diff --git a/client/order.go b/client/order.go index a6ab736..a49c68b 100644 --- a/client/order.go +++ b/client/order.go @@ -119,3 +119,24 @@ func (o Order) GetSupplierOrders(p model.OrderSupplierQuery) (*model.SupplierOrd } return &r.Data, nil } + +// GetSupplierCash ... +func (o Order) GetSupplierCash(p model.OrderSupplierCashReq) (*model.OrderSupplierCashRes, error) { + msg, err := natsio.GetServer().Request(subject.Order.GetSupplierCash, toBytes(p)) + if err != nil { + return nil, err + } + var ( + r struct { + Data model.OrderSupplierCashRes `json:"data"` + Error string `json:"error"` + } + ) + if err = json.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + if r.Error != "" { + return nil, errors.New(r.Error) + } + return &r.Data, nil +} diff --git a/client/withdraw.go b/client/withdraw.go new file mode 100644 index 0000000..006d7a7 --- /dev/null +++ b/client/withdraw.go @@ -0,0 +1,39 @@ +package client + +import ( + "encoding/json" + "errors" + + "git.selly.red/Selly-Modules/natsio" + "git.selly.red/Selly-Modules/natsio/model" + "git.selly.red/Selly-Modules/natsio/subject" +) + +// Withdraw ... +type Withdraw struct{} + +// GetWithdraw ... +func GetWithdraw() Withdraw { + return Withdraw{} +} + +// GetSupplierCash ... +func (o Withdraw) GetSupplierCash(p model.WithdrawSupplierCashReq) (*model.WithdrawSupplierCashRes, error) { + msg, err := natsio.GetServer().Request(subject.Withdraw.GetSupplierCash, toBytes(p)) + if err != nil { + return nil, err + } + var ( + r struct { + Data model.WithdrawSupplierCashRes `json:"data"` + Error string `json:"error"` + } + ) + if err = json.Unmarshal(msg.Data, &r); err != nil { + return nil, err + } + if r.Error != "" { + return nil, errors.New(r.Error) + } + return &r.Data, nil +}