From 1c10210bb96d4e1b2c4688ef55c5e74c8bcd0fe9 Mon Sep 17 00:00:00 2001 From: Tue Date: Tue, 11 Oct 2022 14:13:15 +0700 Subject: [PATCH] rebuild --- client/bank.go | 55 ++++++++++++++++++++++++++++++++++++ client/bank_branch.go | 39 +++++++++++++++++++++++++ model/bank_branch_reponse.go | 11 ++++++++ model/bank_branch_request.go | 6 ++++ model/bank_response.go | 21 ++++++++++++++ subject/bank.go | 17 +++++++++++ 6 files changed, 149 insertions(+) create mode 100644 client/bank.go create mode 100644 client/bank_branch.go create mode 100644 model/bank_branch_reponse.go create mode 100644 model/bank_branch_request.go create mode 100644 model/bank_response.go create mode 100644 subject/bank.go diff --git a/client/bank.go b/client/bank.go new file mode 100644 index 0000000..3391911 --- /dev/null +++ b/client/bank.go @@ -0,0 +1,55 @@ +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" +) + +// Bank ... +type Bank struct{} + +// GetBank ... +func GetBank() Bank { + return Bank{} +} + +func (s Bank) GetBankById(bankID string) (*model.BankBrief, error) { + msg, err := natsio.GetServer().Request(subject.Bank.GetBankById, toBytes(bankID)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.BankBrief `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 Bank) CheckBankAndBranchByID(p model.BankBranchRequest) bool { + msg, err := natsio.GetServer().Request(subject.Bank.CheckBankAndBranchByID, toBytes(p)) + if err != nil { + return false + } + + var r struct { + Error string `json:"error"` + } + + if err = json.Unmarshal(msg.Data, &r); err != nil { + return false + } + return r.Error == "" +} diff --git a/client/bank_branch.go b/client/bank_branch.go new file mode 100644 index 0000000..5890e75 --- /dev/null +++ b/client/bank_branch.go @@ -0,0 +1,39 @@ +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/model/bank_branch_reponse.go b/model/bank_branch_reponse.go new file mode 100644 index 0000000..1fa1432 --- /dev/null +++ b/model/bank_branch_reponse.go @@ -0,0 +1,11 @@ +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 new file mode 100644 index 0000000..6de1216 --- /dev/null +++ b/model/bank_branch_request.go @@ -0,0 +1,6 @@ +package model + +type BankBranchRequest struct { + BankID string `json:"bankId"` + BranchID string `json:"branchId"` +} diff --git a/model/bank_response.go b/model/bank_response.go new file mode 100644 index 0000000..74fc10e --- /dev/null +++ b/model/bank_response.go @@ -0,0 +1,21 @@ +package model + +// MultiLang ... +type MultiLang struct { + En string `json:"en"` + Vi string `json:"vi"` +} + +// 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"` +} diff --git a/subject/bank.go b/subject/bank.go new file mode 100644 index 0000000..9f7f8bb --- /dev/null +++ b/subject/bank.go @@ -0,0 +1,17 @@ +package subject + +import "fmt" + +func getBankValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Bank, val) +} + +var Bank = struct { + GetBankById string + GetBankBranchById string + CheckBankAndBranchByID string +}{ + GetBankById: getBankValue("get_bank_by_id"), + GetBankBranchById: getBankValue("get_bank_branch_by_id"), + CheckBankAndBranchByID: getBankValue("check_bank_and_brach_by_id"), +} -- 2.34.1