natsio/client/order.go

69 lines
1.4 KiB
Go
Raw Permalink Normal View History

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-26 08:56:36 +00:00
msg, err := natsio.GetServer().Request(subject.Order.UpdateORStatus, toBytes(p))
2022-08-20 14:21:51 +00:00
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-29 08:57:18 +00:00
msg, err := natsio.GetServer().Request(subject.Order.CancelDelivery, 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
}
2022-08-31 03:53:51 +00:00
// ChangeDeliveryStatus ...
func (o Order) ChangeDeliveryStatus(p model.OrderChangeDeliveryStatus) error {
msg, err := natsio.GetServer().Request(subject.Order.ChangeDeliveryStatus, 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
}