define order client

This commit is contained in:
Sinh 2022-08-23 14:26:49 +07:00
parent 62206f147c
commit caaa9f098d
4 changed files with 41 additions and 1 deletions

View File

@ -18,7 +18,7 @@ func GetOrder() Order {
}
// UpdateORStatus ...
func (w Order) UpdateORStatus(p model.OrderUpdateORStatus) error {
func (o Order) UpdateORStatus(p model.OrderUpdateORStatus) error {
msg, err := natsio.GetServer().Request(subject.OrderUpdateORStatus, toBytes(p))
if err != nil {
return err
@ -34,3 +34,19 @@ func (w Order) UpdateORStatus(p model.OrderUpdateORStatus) error {
}
return nil
}
// CancelDelivery ...
func (o Order) CancelDelivery(p model.OrderCancelDelivery) error {
msg, err := natsio.GetServer().Request(subject.OrderUpdateORStatus, toBytes(p))
if err != nil {
return err
}
var r model.CommonResponseData
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}

18
model/common_response.go Normal file
View File

@ -0,0 +1,18 @@
package model
import "encoding/json"
// CommonResponseData ...
type CommonResponseData struct {
Data interface{} `json:"data"`
Error string `json:"error"`
}
// ParseData ...
func (c CommonResponseData) ParseData(resultPointer interface{}) error {
b, err := json.Marshal(c.Data)
if err != nil {
return err
}
return json.Unmarshal(b, resultPointer)
}

View File

@ -7,3 +7,8 @@ type OrderUpdateORStatus struct {
Status string `json:"status"`
Reason string `json:"reason"`
}
// OrderCancelDelivery ...
type OrderCancelDelivery struct {
OrderID string `json:"orderId"`
}

View File

@ -4,4 +4,5 @@ const orderPrefix = "order_"
const (
OrderUpdateORStatus = orderPrefix + "update_outbound_request_status"
OrderCancelDelivery = orderPrefix + "cancel_delivery"
)