package client import ( "encoding/json" "errors" "go.mongodb.org/mongo-driver/bson" "git.selly.red/Selly-Modules/natsio" "git.selly.red/Selly-Modules/natsio/model" "git.selly.red/Selly-Modules/natsio/subject" ) // Supplier ... type Supplier struct{} // GetSupplier ... func GetSupplier() Supplier { return Supplier{} } func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) ([]*model.ResponseSupplierInfo, error) { msg, err := natsio.GetServer().Request(subject.Supplier.GetListSupplierInfo, toBytes(p)) if err != nil { return nil, err } var r struct { Data []*model.ResponseSupplierInfo `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 } // GetDetailSupplierInfo ... func (s Supplier) GetDetailSupplierInfo(p model.GetDetailSupplierRequest) (*model.ResponseSupplierInfo, error) { msg, err := natsio.GetServer().Request(subject.Supplier.GetDetailSupplierInfo, toBytes(p)) if err != nil { return nil, err } var r struct { Data *model.ResponseSupplierInfo `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) 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"` } 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) 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) } return r.Data, nil } func (s Supplier) GetBankInfoByID(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"` } 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) Count(req model.SupplierCountReq) (*model.SupplierCountRes, error) { msg, err := natsio.GetServer().Request(subject.Supplier.Count, toBytes(req)) if err != nil { return nil, err } var r struct { Data *model.SupplierCountRes `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 } // SyncWarehouseIntoServiceSupplier ... func (s Supplier) SyncWarehouseIntoServiceSupplier(p model.SyncSupplierWarehousePayload) error { msg, err := natsio.GetServer().Request(subject.Warehouse.SyncWarehouseIntoServiceSupplier, 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 } // GetListWarehouseFreeShip ... func (s Supplier) GetListWarehouseFreeShip() (*model.SupplierListWarehouseFreeShipResponse, error) { msg, err := natsio.GetServer().Request(subject.Supplier.GetListWarehouseFreeShip, toBytes(bson.M{})) if err != nil { return nil, err } var r struct { Data *model.SupplierListWarehouseFreeShipResponse `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 } // GetFreeShipInfo ... func (s Supplier) GetFreeShipInfo(p model.SupplierFreeShipInfoRequestPayload) ([]*model.SupplierFreeShipInfoResponse, error) { msg, err := natsio.GetServer().Request(subject.Supplier.GetFreeShipInfo, toBytes(p)) if err != nil { return nil, err } var r struct { Data []*model.SupplierFreeShipInfoResponse `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 } // 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 } 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 }