From 39614ca4c544430d6ba3930ee041ed662785ceb5 Mon Sep 17 00:00:00 2001 From: anbuiselly <105765792+anbuiselly@users.noreply.github.com> Date: Tue, 10 Jan 2023 11:27:36 +0700 Subject: [PATCH] add get-detail-supplier-info --- client/supplier.go | 22 ++++++++++++++++++++++ model/supplier_request.go | 5 +++++ subject/supplier.go | 2 ++ 3 files changed, 29 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index 9b53826..149aad6 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -38,6 +38,28 @@ func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) ([]*model.Resp 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 { diff --git a/model/supplier_request.go b/model/supplier_request.go index 18034af..5d6fbe2 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -9,6 +9,11 @@ type GetSupplierRequest struct { ListID []primitive.ObjectID `json:"listID"` } +// GetDetailSupplierRequest ... +type GetDetailSupplierRequest struct { + Supplier string `json:"supplier"` +} + type GetSupplierContractRequest struct { SupplierID primitive.ObjectID `json:"supplierID"` } diff --git a/subject/supplier.go b/subject/supplier.go index edc797f..4fc3d32 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -8,12 +8,14 @@ func getSupplierValue(val string) string { var Supplier = struct { GetListSupplierInfo string + GetDetailSupplierInfo string GetSupplierContractBySupplierID string FindAll string FindAllOld string Count string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), + GetDetailSupplierInfo: getSupplierValue("get_detail_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), FindAllOld: getSupplierValue("find_all_old"),