From 9295a8e13f9181cc4546151114f7e1edb387d4e1 Mon Sep 17 00:00:00 2001 From: nguyenphamquangtue <44862367+nguyenphamquangtue@users.noreply.github.com> Date: Wed, 31 Aug 2022 14:48:24 +0700 Subject: [PATCH] Intergrate model for supplier (#15) * build nats supplier * build nats supplier * build nats supplier * build nats supplier --- client/supplier.go | 21 +++++++++++++++++++++ model/supplier_request.go | 10 ++++++++++ model/supplier_response.go | 14 ++++++++++++++ subject/supplier.go | 2 ++ 4 files changed, 47 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index 5b4881a..700d714 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -58,3 +58,24 @@ func (s Supplier) GetSupplierContractBySupplierID(p model.GetSupplierContractReq 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 +} diff --git a/model/supplier_request.go b/model/supplier_request.go index 8372569..04d15d5 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -12,3 +12,13 @@ type GetSupplierRequest struct { type GetSupplierContractRequest struct { SupplierID primitive.ObjectID `json:"supplierID"` } + +// SupplierRequestPayload ... +type SupplierRequestPayload struct { + Limit int + Page int + Keyword string + Status string + PIC string + ContractStatus string +} diff --git a/model/supplier_response.go b/model/supplier_response.go index da33a9f..a87a29e 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -13,3 +13,17 @@ type ResponseSupplierContract struct { Name string `json:"name"` Status string `json:"status"` } + +// SupplierBrief ... +type SupplierBrief struct { + ID string `json:"_id"` + Name string `json:"name"` + Status string `json:"status"` + CreatedAt string `json:"createdAt"` + UpdatedAt string `json:"updatedAt"` +} + +type SupplierAll struct { + Suppliers []SupplierBrief `json:"suppliers"` + Total int64 `json:"total"` +} diff --git a/subject/supplier.go b/subject/supplier.go index b2505cf..17ca8d0 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -9,7 +9,9 @@ func getSupplierValue(val string) string { var Supplier = struct { GetListSupplierInfo string GetSupplierContractBySupplierID string + FindAll string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), + FindAll: getSupplierValue("find_all"), }