Feature/get bank info #23

Open
nguyenphamquangtue wants to merge 15 commits from feature/get-bank-info into master
6 changed files with 87 additions and 0 deletions
Showing only changes of commit b32ceefab1 - Show all commits

39
client/bank.go Normal file
View File

@ -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
}

View File

@ -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
}

6
model/bank_request.go Normal file
View File

@ -0,0 +1,6 @@
package model
// BankRequestPayload ...
type BankRequestPayload struct {
ID string `json:"_id"`
}

6
model/bank_response.go Normal file
View File

@ -0,0 +1,6 @@
package model
// BankBrief ...
type BankBrief struct {
ID string `json:"_id"`
}

13
subject/bank.go Normal file
View File

@ -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"),
}

View File

@ -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",
}