natsio/client/supplier_user.go

161 lines
3.5 KiB
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) CreateSupplierOwnerUsers(p model.CreateOwnerRequest) (*model.CreateOwnerResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateOwnerResponse `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 SupplierUser) UpdateSupplierOwnerUsers(p model.UpdateOwnerRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateOwner, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
func (s SupplierUser) CreateSupplierStaffUsers(p model.CreateStaffRequest) (*model.CreateStaffResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateStaff, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.CreateStaffResponse `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 SupplierUser) UpdateSupplierStaffUsers(p model.UpdateStaffRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStaff, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
func (s SupplierUser) UpdateStatus(p model.UpdateStatusRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStaff, toBytes(p))
if err != nil {
return err
}
var r struct {
Error string `json:"error"`
}
if err = json.Unmarshal(msg.Data, &r); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
func (s SupplierUser) ResetPassword(p model.ResetPasswordRequest) (*model.ResetPasswordResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.ResetPassword, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.ResetPasswordResponse `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
}
// CheckTokenSupplierUser ...
func (s SupplierUser) CheckTokenSupplierUser(p model.CheckTokenSupplierUserPayload) (*model.ResponseCheckTokenSupplierUser, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CheckTokenSupplierUser, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Error string `json:"error"`
Data *model.ResponseCheckTokenSupplierUser `json:"data"`
}
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
}