2022-08-20 14:21:51 +00:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"errors"
|
|
|
|
|
|
|
|
"github.com/Selly-Modules/natsio"
|
|
|
|
"github.com/Selly-Modules/natsio/model"
|
|
|
|
"github.com/Selly-Modules/natsio/subject"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Order ...
|
|
|
|
type Order struct{}
|
|
|
|
|
|
|
|
// GetOrder ...
|
|
|
|
func GetOrder() Order {
|
|
|
|
return Order{}
|
|
|
|
}
|
|
|
|
|
|
|
|
// UpdateORStatus ...
|
2022-08-23 07:26:49 +00:00
|
|
|
func (o Order) UpdateORStatus(p model.OrderUpdateORStatus) error {
|
2022-08-20 14:21:51 +00:00
|
|
|
msg, err := natsio.GetServer().Request(subject.OrderUpdateORStatus, toBytes(p))
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
var r struct {
|
|
|
|
Error string `json:"error"`
|
|
|
|
}
|
|
|
|
if err = json.Unmarshal(msg.Data, &r); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if r.Error != "" {
|
|
|
|
return errors.New(r.Error)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
2022-08-23 07:26:49 +00:00
|
|
|
|
|
|
|
// CancelDelivery ...
|
|
|
|
func (o Order) CancelDelivery(p model.OrderCancelDelivery) error {
|
2022-08-26 04:25:09 +00:00
|
|
|
msg, err := natsio.GetServer().Request(subject.OrderCancelDelivery, toBytes(p))
|
2022-08-23 07:26:49 +00:00
|
|
|
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
|
|
|
|
}
|