package client import ( "encoding/json" "errors" "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 } 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 } // CreateWarehouseIntoServiceSupplier ... func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWarehousePayload) error { msg, err := natsio.GetServer().Request(subject.Warehouse.CreateWarehouseIntoServiceSupplier, 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 } // UpdateWarehouseIntoServiceSupplier ... func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWarehousePayload) error { msg, err := natsio.GetServer().Request(subject.Warehouse.UpdateWarehouseIntoServiceSupplier, 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 } // CheckTokenSupplier ... func (s Supplier) CheckTokenSupplier(p model.CheckTokenSupplierPayload) (*model.ResponseSupplierInfo, error) { msg, err := natsio.GetServer().Request(subject.Supplier.CheckTokenSupplier, toBytes(p)) if err != nil { return nil, err } var r struct { Error string `json:"error"` Data *model.ResponseSupplierInfo `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 }