From b7d963cc90a9916d5d05fe77a5f6a915a256086d Mon Sep 17 00:00:00 2001 From: QuanTT0110 Date: Mon, 17 Oct 2022 15:09:50 +0700 Subject: [PATCH] get list warehouse freeship --- client/supplier.go | 23 +++++++++++++++++++++++ model/supplier_response.go | 4 ++++ subject/supplier.go | 2 ++ 3 files changed, 29 insertions(+) diff --git a/client/supplier.go b/client/supplier.go index 0452b82..b091b78 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -3,6 +3,7 @@ package client import ( "encoding/json" "errors" + "go.mongodb.org/mongo-driver/bson" "git.selly.red/Selly-Modules/natsio" "git.selly.red/Selly-Modules/natsio/model" @@ -115,3 +116,25 @@ func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWareh } return nil } + +// GetWarehouseFreeship ... +func (s Supplier) GetWarehouseFreeship() (*model.ResponseListWarehouseIDByBusinessType, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.GetListWarehouseFreeship, toBytes(bson.M{})) + if err != nil { + return nil, err + } + + var r struct { + Data *model.ResponseListWarehouseIDByBusinessType `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_response.go b/model/supplier_response.go index 975a8de..3796e50 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 ResponseListWarehouseIDByBusinessType struct { + Warehouses []string `json:"warehouses"` +} diff --git a/subject/supplier.go b/subject/supplier.go index 17ca8d0..f249ef1 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -10,8 +10,10 @@ var Supplier = struct { GetListSupplierInfo string GetSupplierContractBySupplierID string FindAll string + GetListWarehouseFreeship string }{ GetListSupplierInfo: getSupplierValue("get_list_supplier_info"), GetSupplierContractBySupplierID: getSupplierValue("get_supplier_contract_by_supplier_id"), FindAll: getSupplierValue("find_all"), + GetListWarehouseFreeship: getSupplierValue("get_list_warehouse_freeship"), }