From b32ceefab18129fdd9a1d2097d78cc52a1eea14a Mon Sep 17 00:00:00 2001 From: Tue Date: Wed, 14 Sep 2022 14:09:48 +0700 Subject: [PATCH] add bank info --- client/bank.go | 39 +++++++++++++++++++++++++++++++++++++++ client/supplier.go | 21 +++++++++++++++++++++ model/bank_request.go | 6 ++++++ model/bank_response.go | 6 ++++++ subject/bank.go | 13 +++++++++++++ subject/config.go | 2 ++ 6 files changed, 87 insertions(+) create mode 100644 client/bank.go create mode 100644 model/bank_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..f083e8f --- /dev/null +++ b/client/bank.go @@ -0,0 +1,39 @@ +package client + +import ( + "encoding/json" + "errors" + + "github.com/Selly-Modules/natsio" + "github.com/Selly-Modules/natsio/model" + "github.com/Selly-Modules/natsio/subject" +) + +// Bank ... +type Bank struct{} + +// GetBank ... +func GetBank() Bank { + return Bank{} +} + +func (s Bank) GetBankInfoByID(bankID model.BankRequestPayload) (*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 +} diff --git a/client/supplier.go b/client/supplier.go index 700d714..02d2875 100644 --- a/client/supplier.go +++ b/client/supplier.go @@ -79,3 +79,24 @@ func (s Supplier) FindAll(supplierID model.SupplierRequestPayload) (*model.Suppl return r.Data, nil } + +func (s Supplier) GetBankInfoByID(supplierID model.SupplierRequestPayload) (*model.SupplierAll, error) { + msg, err := natsio.GetServer().Request(subject.Supplier.FindAll, toBytes(supplierID)) + if err != nil { + return nil, err + } + + var r struct { + Data *model.SupplierAll `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_request.go b/model/bank_request.go new file mode 100644 index 0000000..2093aca --- /dev/null +++ b/model/bank_request.go @@ -0,0 +1,6 @@ +package model + +// BankRequestPayload ... +type BankRequestPayload struct { + ID string `json:"_id"` +} diff --git a/model/bank_response.go b/model/bank_response.go new file mode 100644 index 0000000..917b81c --- /dev/null +++ b/model/bank_response.go @@ -0,0 +1,6 @@ +package model + +// BankBrief ... +type BankBrief struct { + ID string `json:"_id"` +} diff --git a/subject/bank.go b/subject/bank.go new file mode 100644 index 0000000..71bbdbe --- /dev/null +++ b/subject/bank.go @@ -0,0 +1,13 @@ +package subject + +import "fmt" + +func getBankValue(val string) string { + return fmt.Sprintf("%s.%s", prefixes.Bank, val) +} + +var Bank = struct { + GetBankById string +}{ + GetBankById: getBankValue("get_bank_by_id"), +} diff --git a/subject/config.go b/subject/config.go index dfeea56..47b62a1 100644 --- a/subject/config.go +++ b/subject/config.go @@ -5,6 +5,7 @@ var prefixes = struct { Order string Warehouse string Location string + Bank string Supplier string }{ Communication: "communication", @@ -12,4 +13,5 @@ var prefixes = struct { Warehouse: "warehouse", Location: "location", Supplier: "supplier", + Bank: "bank", }