39 lines
859 B
Go
39 lines
859 B
Go
|
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"
|
||
|
)
|
||
|
|
||
|
// SupplierUser ...
|
||
|
type SupplierUser struct{}
|
||
|
|
||
|
// GetSupplierUser ...
|
||
|
func GetSupplierUser() SupplierUser {
|
||
|
return SupplierUser{}
|
||
|
}
|
||
|
|
||
|
func (s SupplierUser) CreateSupplierUserS(p model.CreateSupplierUserRequest) (*model.CreateSupplierUserResponse, error) {
|
||
|
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateSupplierUser, toBytes(p))
|
||
|
if err != nil {
|
||
|
return nil, err
|
||
|
}
|
||
|
|
||
|
var r struct {
|
||
|
Data *model.CreateSupplierUserResponse `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
|
||
|
}
|