diff --git a/client/supplier.go b/client/supplier.go index 7c19bd6..02bf82d 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -123,6 +123,27 @@ func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*mod 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)) diff --git a/model/supplier_request.go b/model/supplier_request.go index bd3714f..0cfa72f 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -55,3 +55,8 @@ type SupplierFindAllReq struct { Segment string `json:"segment"` IDs []string `json:"ids"` } + +type SupplierCountReq struct { + Segment string `json:"segment"` + IDs []string `json:"ids"` +} diff --git a/model/supplier_response.go b/model/supplier_response.go index 690f8f7..9e20e27 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -80,3 +80,7 @@ type SyncSupplierWarehousePayload struct { DistrictCode int `json:"districtCode"` WardCode int `json:"wardCode"` } + +type SupplierCountRes struct { + Total int64 `json:"total"` +} diff --git a/subject/supplier.go b/subject/supplier.go index 03bb0aa..931a3e7 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -17,6 +17,7 @@ var Supplier = struct { GetCurrentBalance string GetFreeShipInfo string FindAllOld string + Count string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), @@ -28,4 +29,5 @@ var Supplier = struct { GetCurrentBalance: getSupplierValue("get_current_balance"), GetFreeShipInfo: getSupplierValue("get_free_ship_info"), FindAllOld: getSupplierValue("find_all_old"), + Count: getSupplierValue("count"), }