From d29ad11fa5f2389b2911f951b0dabb1f1c3836d7 Mon Sep 17 00:00:00 2001 From: Tue Date: Wed, 31 Aug 2022 14:41:06 +0700 Subject: [PATCH] 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 {