natsio/client/supplier.go

256 lines
6.3 KiB
Go
Raw Normal View History

2022-08-26 10:15:49 +00:00
package client
import (
"encoding/json"
"errors"
2022-10-17 08:09:50 +00:00
"go.mongodb.org/mongo-driver/bson"
2022-08-26 10:15:49 +00:00
2022-10-10 04:11:39 +00:00
"git.selly.red/Selly-Modules/natsio"
"git.selly.red/Selly-Modules/natsio/model"
"git.selly.red/Selly-Modules/natsio/subject"
2022-08-26 10:15:49 +00:00
)
// Supplier ...
type Supplier struct{}
2022-08-26 16:37:01 +00:00
// GetSupplier ...
func GetSupplier() Supplier {
return Supplier{}
}
2022-08-29 07:37:45 +00:00
func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) ([]*model.ResponseSupplierInfo, error) {
2022-08-29 07:25:12 +00:00
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-29 07:37:45 +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
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
}
func (s Supplier) FindAll(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID))
if err != nil {
return nil, err
}
var r struct {
Data *model.SupplierAll `json:"data"`
Error string `json:"error"`
}
2022-09-14 07:09:48 +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-09-14 07:09:48 +00:00
2022-11-18 03:13:41 +00:00
func (s Supplier) FindAllOld(req model.SupplierFindAllReq) (*model.SupplierAll, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.FindAllOld, toBytes(req))
if err != nil {
return nil, err
}
var r struct {
Data *model.SupplierAll `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)
}
2022-09-14 07:09:48 +00:00
return r.Data, nil
}
2022-09-14 10:33:18 +00:00
2022-09-14 07:09:48 +00:00
func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID))
2022-09-14 10:33:18 +00:00
if err != nil {
2022-09-14 07:09:48 +00:00
return nil, err
2022-09-14 10:33:18 +00:00
}
2022-09-14 07:09:48 +00:00
2022-09-14 10:33:18 +00:00
var r struct {
2022-09-14 07:09:48 +00:00
Data *model.SupplierAll `json:"data"`
Error string `json:"error"`
2022-09-14 10:33:18 +00:00
}
2022-09-14 07:09:48 +00:00
2022-09-14 10:33:18 +00:00
if err = json.Unmarshal(msg.Data, &r); err != nil {
2022-09-14 07:09:48 +00:00
return nil, err
2022-09-14 10:33:18 +00:00
}
if r.Error != "" {
2022-09-14 07:09:48 +00:00
return nil, errors.New(r.Error)
2022-09-14 10:33:18 +00:00
}
2022-09-14 07:09:48 +00:00
return r.Data, nil
2022-09-14 10:33:18 +00:00
}
2022-09-14 16:30:22 +00:00
// SyncWarehouseIntoServiceSupplier ...
func (s Supplier) SyncWarehouseIntoServiceSupplier(p model.SyncSupplierWarehousePayload) error {
msg, err := natsio.GetServer().Request(subject.Warehouse.SyncWarehouseIntoServiceSupplier, toBytes(p))
2022-09-14 16:30:22 +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-10-17 08:09:50 +00:00
2022-10-28 04:19:15 +00:00
// GetListWarehouseFreeShip ...
func (s Supplier) GetListWarehouseFreeShip() (*model.SupplierListWarehouseFreeShipResponse, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.GetListWarehouseFreeShip, toBytes(bson.M{}))
2022-10-17 08:09:50 +00:00
if err != nil {
return nil, err
}
var r struct {
2022-10-28 04:19:15 +00:00
Data *model.SupplierListWarehouseFreeShipResponse `json:"data"`
2022-10-17 08:09:50 +00:00
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-10-27 08:52:39 +00:00
// GetFreeShipInfo ...
2022-10-28 04:19:15 +00:00
func (s Supplier) GetFreeShipInfo(p model.SupplierFreeShipInfoRequestPayload) ([]*model.SupplierFreeShipInfoResponse, error) {
2022-10-27 08:52:39 +00:00
msg, err := natsio.GetServer().Request(subject.Supplier.GetFreeShipInfo, toBytes(p))
2022-10-25 05:00:37 +00:00
if err != nil {
return nil, err
}
var r struct {
2022-10-27 08:52:39 +00:00
Data []*model.SupplierFreeShipInfoResponse `json:"data"`
Error string `json:"error"`
2022-10-25 05:00:37 +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-10-27 02:41:38 +00:00
2022-10-26 10:56:15 +00:00
// CreateCashflow ...
func (s Supplier) CreateCashflow(p model.SupplierCashflowCreatePayload) (*model.SupplierCashflowCreateResponse, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.CreateCashflow, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Error string `json:"error"`
Data *model.SupplierCashflowCreateResponse `json:"data"`
}
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-11-03 09:02:43 +00:00
func (s Supplier) UpdateBalance(p model.SupplierUpdateBalanceReq) (*model.SupplierUpdateBalanceRes, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.UpdateBalance, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Error string `json:"error"`
Data *model.SupplierUpdateBalanceRes `json:"data"`
}
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
}
func (s Supplier) GetCurrentBalance(p model.SupplierGetCurrentBalanceReq) (*model.SupplierGetCurrentBalanceRes, error) {
msg, err := natsio.GetServer().Request(subject.Supplier.GetCurrentBalance, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Error string `json:"error"`
Data *model.SupplierGetCurrentBalanceRes `json:"data"`
}
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
}
func (s Supplier) DeleteCashflow(p model.SupplierDeleteCashflowReq) error {
msg, err := natsio.GetServer().Request(subject.Supplier.DeleteCashflow, 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
}