From 8248069bb86310fb30d839ff03d50553ea508530 Mon Sep 17 00:00:00 2001 From: Sinh Date: Wed, 23 Nov 2022 10:08:52 +0700 Subject: [PATCH] count supplier --- client/supplier.go | 21 +++++++++++++++++++++ model/supplier_request.go | 5 +++++ model/supplier_response.go | 4 ++++ subject/supplier.go | 2 ++ 4 files changed, 32 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index e278f46..9b53826 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -122,6 +122,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 +} + // CreateWarehouseIntoServiceSupplier ... func (s Supplier) CreateWarehouseIntoServiceSupplier(p model.CreateSupplierWarehousePayload) error { msg, err := natsio.GetServer().Request(subject.Warehouse.CreateWarehouseIntoServiceSupplier, toBytes(p)) diff --git a/model/supplier_request.go b/model/supplier_request.go index 118737d..bbba857 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -45,3 +45,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 975a8de..2b9dd10 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -29,3 +29,7 @@ type SupplierAll struct { Suppliers []SupplierBrief `json:"suppliers"` Total int64 `json:"total"` } + +type SupplierCountRes struct { + Total int64 `json:"total"` +} diff --git a/subject/supplier.go b/subject/supplier.go index 92af7b3..edc797f 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -11,9 +11,11 @@ var Supplier = struct { GetSupplierContractBySupplierID string FindAll string FindAllOld string + Count string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), FindAllOld: getSupplierValue("find_all_old"), + Count: getSupplierValue("count"), }