natsio/client/bank.go

79 lines
1.6 KiB
Go
Raw Normal View History

2022-10-11 07:13:15 +00:00
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{}
}
2022-11-08 06:53:52 +00:00
// GetBankInfo ...
func (s Bank) GetBankInfo(p []model.GetBankInfoRequest) ([]*model.ResponseBankInfo, error) {
msg, err := natsio.GetServer().Request(subject.Bank.GetBankInfo, toBytes(p))
2022-10-11 07:13:15 +00:00
if err != nil {
return nil, err
}
var r struct {
2022-11-08 06:53:52 +00:00
Data []*model.ResponseBankInfo `json:"data"`
Error string `json:"error"`
2022-10-11 07:13:15 +00:00
}
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
}
2022-11-08 06:53:52 +00:00
func (s Bank) CheckBankAndBranchByID(p model.CheckBankAndBranchByIDRequest) bool {
2022-10-11 07:13:15 +00:00
msg, err := natsio.GetServer().Request(subject.Bank.CheckBankAndBranchByID, toBytes(p))
if err != nil {
return false
}
var r struct {
2022-11-09 07:28:10 +00:00
Data bool `json:"data"`
2022-10-11 07:13:15 +00:00
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return false
}
2022-11-09 07:28:10 +00:00
return r.Data
}
// GetBankAndBranchDetail ...
func (s Bank) GetBankAndBranchDetail(p model.GetBankInfoRequest) (*model.ResponseBankInfo, error) {
msg, err := natsio.GetServer().Request(subject.Bank.GetBankInfoDetail, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResponseBankInfo `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
2022-10-11 07:13:15 +00:00
}