From 27b14aa1228f302b64cc7ffd63a1e52632981fc2 Mon Sep 17 00:00:00 2001 From: QuanTT0110 Date: Tue, 25 Oct 2022 12:00:37 +0700 Subject: [PATCH] get freeships by supplier ids --- client/supplier.go | 19 +++++++++++++++++++ model/supplier_request.go | 4 ++++ model/supplier_response.go | 11 +++++++++++ subject/config.go | 2 ++ subject/selly.go | 13 +++++++++++++ 5 files changed, 49 insertions(+) create mode 100644 subject/selly.go diff --git a/client/supplier.go b/client/supplier.go index b091b78..65553a1 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -138,3 +138,22 @@ func (s Supplier) GetWarehouseFreeship() (*model.ResponseListWarehouseIDByBusine return r.Data, nil } + +// GetFreeshipsBySupplierIDs ... +func (s Supplier) GetFreeshipsBySupplierIDs(p model.GetFreeshipsBySupplierIds) (*model.ResponseListFreeshipsBySupplierIds, error) { + msg, err := natsio.GetServer().Request(subject.Selly.GetFreeshipsBySupplierIds, toBytes(p)) + if err != nil { + return nil, err + } + var r struct { + Data *model.ResponseListFreeshipsBySupplierIds `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 5a19924..d0d7d68 100644 --- a/model/supplier_request.go +++ b/model/supplier_request.go @@ -38,3 +38,7 @@ type UpdateSupplierWarehousePayload struct { DistrictCode int `json:"districtCode"` WardCode int `json:"wardCode"` } + +type GetFreeshipsBySupplierIds struct { + SupplierIDs []string `json:"supplierIds"` +} diff --git a/model/supplier_response.go b/model/supplier_response.go index 3796e50..eaebef5 100644 --- a/model/supplier_response.go +++ b/model/supplier_response.go @@ -33,3 +33,14 @@ type SupplierAll struct { type ResponseListWarehouseIDByBusinessType struct { Warehouses []string `json:"warehouses"` } + +type Freeship struct { + ID string `json:"_id"` + ShortName string `json:"shortName"` + MilestoneText []string `json:"milestoneText"` +} + +type ResponseListFreeshipsBySupplierIds struct { + SupplierID string `json:"supplierId"` + Freeships []Freeship `json:"freeships"` +} diff --git a/subject/config.go b/subject/config.go index ccc480e..916e22d 100644 --- a/subject/config.go +++ b/subject/config.go @@ -10,6 +10,7 @@ var prefixes = struct { Supplier string Seller string AuthSMS string + Selly string }{ Communication: "communication", Order: "order", @@ -20,4 +21,5 @@ var prefixes = struct { Bank: "bank", Seller: "seller", AuthSMS: "auth_sms", + Selly: "selly", } diff --git a/subject/selly.go b/subject/selly.go new file mode 100644 index 0000000..27494cd --- /dev/null +++ b/subject/selly.go @@ -0,0 +1,13 @@ +package subject + +import "fmt" + +func getSellyValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Selly, val) +} + +var Selly = struct { + GetFreeshipsBySupplierIds string +}{ + GetFreeshipsBySupplierIds: getSellyValue("get_freeships_by_supplier_ids"), +}