From 30b0238c0f798daa515f0ea07be453c327977925 Mon Sep 17 00:00:00 2001 From: Tue Date: Wed, 31 Aug 2022 14:18:04 +0700 Subject: [PATCH 1/4] build nats supplier --- client/supplier.go | 10 +++++----- model/supplier_request.go | 11 ++++++----- model/supplier_response.go | 16 ++++++++++++---- subject/supplier.go | 4 ++-- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/client/supplier.go b/client/supplier.go index 01da757..4e4d938 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -17,18 +17,18 @@ func GetSupplier() Supplier { return Supplier{} } -func (s Supplier) GetSupplierInfo(supplierID model.GetSupplierRequest) (*model.ResponseSupplierInfo, error) { - msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierInfo, toBytes(supplierID)) +func (s Supplier) FindAll(supplierID model.GetSupplierRequest) (*model.SupplierAll, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID)) if err != nil { return nil, err } var r struct { - Data *model.ResponseSupplierInfo `json:"data"` - Error string `json:"error"` + Data *model.SupplierAll `json:"data"` + Error string `json:"error"` } - if err := json.Unmarshal(msg.Data, &r); err != nil { + if err = json.Unmarshal(msg.Data, &r); err != nil { return nil, err } if r.Error != "" { diff --git a/model/supplier_request.go b/model/supplier_request.go index 2fede05..52806ba 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -1,10 +1,11 @@ package model -import ( - "go.mongodb.org/mongo-driver/bson/primitive" -) - // GetSupplierRequest ... type GetSupplierRequest struct { - ID primitive.ObjectID `json:"_id"` + 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 de2f579..23c0f1b 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -1,7 +1,15 @@ package model -// ResponseSupplierInfo ... -type ResponseSupplierInfo struct { - ID string `json:"id"` - Name string `json:"name"` +// 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 4b4cf52..557fc77 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -7,7 +7,7 @@ func getSupplierValue(val string) string { } var Supplier = struct { - GetSupplierInfo string + FindAll string }{ - GetSupplierInfo: getSupplierValue("get_supplier_info"), + FindAll: getSupplierValue("find_all"), } -- 2.34.1 From c49194539507f0e2001c8aac57ba5c74ea5a8dbb Mon Sep 17 00:00:00 2001 From: Tue Date: Wed, 31 Aug 2022 14:36:04 +0700 Subject: [PATCH 2/4] build nats supplier --- client/supplier.go | 8 ++++---- subject/supplier.go | 2 -- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/client/supplier.go b/client/supplier.go index 3dd028c..62592b0 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -17,15 +17,15 @@ func GetSupplier() Supplier { return Supplier{} } -func (s Supplier) GetSupplierInfo(supplierID model.GetSupplierRequest) (*model.ResponseSupplierInfo, error) { - msg, err := natsio.GetServer().Request(subject.Supplier.GetSupplierInfo, toBytes(supplierID)) +func (s Supplier) GetListSupplierInfo(supplierID model.GetSupplierRequest) ([]*model.ResponseSupplierInfo, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.GetListSupplierInfo, toBytes(supplierID)) if err != nil { return nil, err } var r struct { - Data *model.ResponseSupplierInfo `json:"data"` - Error string `json:"error"` + Data []*model.ResponseSupplierInfo `json:"data"` + Error string `json:"error"` } if err := json.Unmarshal(msg.Data, &r); err != nil { diff --git a/subject/supplier.go b/subject/supplier.go index 573b25e..17ca8d0 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -7,12 +7,10 @@ func getSupplierValue(val string) string { } var Supplier = struct { - GetSupplierInfo string GetListSupplierInfo string GetSupplierContractBySupplierID string FindAll string }{ - GetSupplierInfo: getSupplierValue("get_supplier_info"), GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), -- 2.34.1 From ed48d806650b32cc2f84269cf021a5ed3a1e0150 Mon Sep 17 00:00:00 2001 From: Tue Date: Wed, 31 Aug 2022 14:37:56 +0700 Subject: [PATCH 3/4] build nats supplier --- client/supplier.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client/supplier.go b/client/supplier.go index 62592b0..7ec8d50 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -17,8 +17,8 @@ func GetSupplier() Supplier { return Supplier{} } -func (s Supplier) GetListSupplierInfo(supplierID model.GetSupplierRequest) ([]*model.ResponseSupplierInfo, error) { - msg, err := natsio.GetServer().Request(subject.Supplier.GetListSupplierInfo, toBytes(supplierID)) +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 } -- 2.34.1 From d29ad11fa5f2389b2911f951b0dabb1f1c3836d7 Mon Sep 17 00:00:00 2001 From: Tue Date: Wed, 31 Aug 2022 14:41:06 +0700 Subject: [PATCH 4/4] build nats supplier --- client/supplier.go | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index 7ec8d50..700d714 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -38,6 +38,27 @@ func (s Supplier) GetListSupplierInfo(p model.GetSupplierRequest) ([]*model.Resp 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 { -- 2.34.1