natsio/client/supplier.go

82 lines
1.8 KiB
Go
Raw Normal View History

2022-08-26 10:15:49 +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"
)
// Supplier ...
type Supplier struct{}
2022-08-26 16:37:01 +00:00
// GetSupplier ...
func GetSupplier() Supplier {
return Supplier{}
}
2022-08-31 07:37:56 +00:00
func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) ([]*model.ResponseSupplierInfo, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.GetListSupplierInfo, toBytes(p))
2022-08-26 10:15:49 +00:00
if err != nil {
return nil, err
}
var r struct {
2022-08-31 07:36:04 +00:00
Data []*model.ResponseSupplierInfo `json:"data"`
Error string `json:"error"`
2022-08-26 10:15:49 +00:00
}
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
}
2022-08-29 07:25:12 +00:00
2022-08-31 07:41:06 +00:00
func (s Supplier) GetSupplierContractBySupplierID(p model.GetSupplierContractRequest) (*model.ResponseSupplierContract, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierContractBySupplierID, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseSupplierContract `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
}
2022-08-31 07:29:11 +00:00
func (s Supplier) FindAll(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) {
2022-08-31 07:18:04 +00:00
msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID))
2022-08-26 10:15:49 +00:00
if err != nil {
return nil, err
}
var r struct {
2022-08-31 07:18:04 +00:00
Data *model.SupplierAll `json:"data"`
Error string `json:"error"`
2022-08-26 10:15:49 +00:00
}
2022-08-31 07:18:04 +00:00
if err = json.Unmarshal(msg.Data, &r); err != nil {
2022-08-26 10:15:49 +00:00
return nil, err
}
if r.Error != "" {
return nil, errors.New(r.Error)
}
return r.Data, nil
}