From 27b14aa1228f302b64cc7ffd63a1e52632981fc2 Mon Sep 17 00:00:00 2001 From: QuanTT0110 Date: Tue, 25 Oct 2022 12:00:37 +0700 Subject: [PATCH 1/2] 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"), +} From 33bc508f1f648b46f21fe89c767d5597c1ce1a17 Mon Sep 17 00:00:00 2001 From: QuanTT0110 Date: Thu, 27 Oct 2022 09:37:07 +0700 Subject: [PATCH 2/2] get bank and branches by bank ids --- client/bank.go | 10 ++++----- client/bank_branch.go | 39 ------------------------------------ client/supplier.go | 2 +- model/bank_branch_reponse.go | 11 ---------- model/bank_branch_request.go | 6 ------ model/bank_request.go | 10 +++++++++ model/bank_response.go | 39 +++++++++++++++++++++++++++--------- subject/bank.go | 10 ++++----- subject/selly.go | 2 ++ subject/supplier.go | 2 -- 10 files changed, 51 insertions(+), 80 deletions(-) delete mode 100644 client/bank_branch.go delete mode 100644 model/bank_branch_reponse.go delete mode 100644 model/bank_branch_request.go create mode 100644 model/bank_request.go diff --git a/client/bank.go b/client/bank.go index 3391911..69e6d26 100644 --- a/client/bank.go +++ b/client/bank.go @@ -17,15 +17,15 @@ func GetBank() Bank { return Bank{} } -func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) { - msg, err := natsio.GetServer().Request(subject.Bank.GetBankById, toBytes(bankID)) +func (s Bank) GetBankAndBranchByBankIDs(p model.GetBankAndBranchesRequest) ([]*model.ResponseBankAndBranches, error) { + msg, err := natsio.GetServer().Request(subject.Bank.GetBankAndBranchesByBankIDs, toBytes(p)) if err != nil { return nil, err } var r struct { - Data *model.BankBrief `json:"data"` - Error string `json:"error"` + Data []*model.ResponseBankAndBranches `json:"data"` + Error string `json:"error"` } if err = json.Unmarshal(msg.Data, &r); err != nil { @@ -38,7 +38,7 @@ func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) { return r.Data, nil } -func (s Bank) CheckBankAndBranchByID(p model.BankBranchRequest) bool { +func (s Bank) CheckBankAndBranchByID(p model.CheckBankAndBranchByIDRequest) bool { msg, err := natsio.GetServer().Request(subject.Bank.CheckBankAndBranchByID, toBytes(p)) if err != nil { return false diff --git a/client/bank_branch.go b/client/bank_branch.go deleted file mode 100644 index 5890e75..0000000 --- a/client/bank_branch.go +++ /dev/null @@ -1,39 +0,0 @@ -package client - -import ( - "encoding/json" - "errors" - - "git.selly.red/Selly-Modules/natsio" - "git.selly.red/Selly-Modules/natsio/model" - "git.selly.red/Selly-Modules/natsio/subject" -) - -// BankBranch ... -type BankBranch struct{} - -// GetBankBranch ... -func GetBankBranch() BankBranch { - return BankBranch{} -} - -func (s BankBranch) GetBankBranchById(bankBranchID string) (*model.BankBranchBrief, error) { - msg, err := natsio.GetServer().Request(subject.Bank.GetBankBranchById, toBytes(bankBranchID)) - if err != nil { - return nil, err - } - - var r struct { - Data *model.BankBranchBrief `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/client/supplier.go b/client/supplier.go index 65553a1..f9bbb6d 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -119,7 +119,7 @@ func (s Supplier) UpdateWarehouseIntoServiceSupplier(p model.UpdateSupplierWareh // GetWarehouseFreeship ... func (s Supplier) GetWarehouseFreeship() (*model.ResponseListWarehouseIDByBusinessType, error) { - msg, err := natsio.GetServer().Request(subject.Supplier.GetListWarehouseFreeship, toBytes(bson.M{})) + msg, err := natsio.GetServer().Request(subject.Selly.GetListWarehouseFreeship, toBytes(bson.M{})) if err != nil { return nil, err } diff --git a/model/bank_branch_reponse.go b/model/bank_branch_reponse.go deleted file mode 100644 index 1fa1432..0000000 --- a/model/bank_branch_reponse.go +++ /dev/null @@ -1,11 +0,0 @@ -package model - -// BankBranchBrief ... -type BankBranchBrief struct { - ID string `json:"_id"` - City string `json:"city"` - BankCode string `json:"bankCode"` - Bank string `json:"bank"` - Active bool `json:"active"` - Name string `json:"name"` -} diff --git a/model/bank_branch_request.go b/model/bank_branch_request.go deleted file mode 100644 index 6de1216..0000000 --- a/model/bank_branch_request.go +++ /dev/null @@ -1,6 +0,0 @@ -package model - -type BankBranchRequest struct { - BankID string `json:"bankId"` - BranchID string `json:"branchId"` -} diff --git a/model/bank_request.go b/model/bank_request.go new file mode 100644 index 0000000..f53b794 --- /dev/null +++ b/model/bank_request.go @@ -0,0 +1,10 @@ +package model + +type CheckBankAndBranchByIDRequest struct { + BankID string `json:"bankId"` + BranchID string `json:"branchId"` +} + +type GetBankAndBranchesRequest struct { + BankIDs []string `json:"bankIds"` +} diff --git a/model/bank_response.go b/model/bank_response.go index 74fc10e..565cf21 100644 --- a/model/bank_response.go +++ b/model/bank_response.go @@ -1,21 +1,40 @@ package model +import "time" + // MultiLang ... type MultiLang struct { En string `json:"en"` Vi string `json:"vi"` } +// BankBranchBrief ... +type BranchBrief struct { + ID string `json:"_id"` + City string `json:"city"` + BankCode string `json:"bankCode"` + BankID string `json:"bankId"` + Active bool `json:"active"` + Name string `json:"name"` +} + // BankBrief ... type BankBrief struct { - ID string `json:"_id"` - Name MultiLang `json:"name"` - ShortName string `json:"shortName"` - Active bool `json:"active"` - BenBankName string `json:"benBankName"` - BankCode int `json:"bankCode"` - IsBranchRequired bool `json:"isBranchRequired"` - SearchString string `json:"searchString"` - BeneficiaryForVietinbank string `json:"beneficiaryForVietinbank"` - CreatedBy string `json:"createdBy,omitempty"` + ID string `json:"_id"` + Name MultiLang `json:"name"` + ShortName string `json:"shortName"` + Active bool `json:"active"` + BenBankName string `json:"benBankName"` + BankCode int `json:"bankCode"` + IsBranchRequired bool `json:"isBranchRequired"` + BeneficiaryForVietinbank string `json:"beneficiaryForVietinbank"` + CreatedBy string `json:"createdBy,omitempty"` + CreatedAt time.Time `json:"createdAt"` + BranchTotal int64 `json:"branchTotal"` + Logo interface{} `json:"logo"` +} + +type ResponseBankAndBranches struct { + Bank BankBrief `json:"bank"` + Branches []BranchBrief `json:"branches"` } diff --git a/subject/bank.go b/subject/bank.go index 9f7f8bb..caf8fa1 100644 --- a/subject/bank.go +++ b/subject/bank.go @@ -7,11 +7,9 @@ func getBankValue(val string) string { } var Bank = struct { - GetBankById string - GetBankBranchById string - CheckBankAndBranchByID string + GetBankAndBranchesByBankIDs string + CheckBankAndBranchByID string }{ - GetBankById: getBankValue("get_bank_by_id"), - GetBankBranchById: getBankValue("get_bank_branch_by_id"), - CheckBankAndBranchByID: getBankValue("check_bank_and_brach_by_id"), + GetBankAndBranchesByBankIDs: getBankValue("get_bank_and_branches_by_bank_ids"), + CheckBankAndBranchByID: getBankValue("check_bank_and_branch_by_id"), } diff --git a/subject/selly.go b/subject/selly.go index 27494cd..f4b6010 100644 --- a/subject/selly.go +++ b/subject/selly.go @@ -8,6 +8,8 @@ func getSellyValue(val string) string { var Selly = struct { GetFreeshipsBySupplierIds string + GetListWarehouseFreeship string }{ GetFreeshipsBySupplierIds: getSellyValue("get_freeships_by_supplier_ids"), + GetListWarehouseFreeship: getSupplierValue("get_list_warehouse_freeship"), } diff --git a/subject/supplier.go b/subject/supplier.go index f249ef1..17ca8d0 100644 --- a/subject/supplier.go +++ b/subject/supplier.go @@ -10,10 +10,8 @@ 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"), }