natsio/client/supplier_user.go

183 lines
3.9 KiB
Go
Raw Normal View History

2022-10-25 08:27:05 +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"
)
// SupplierUser ...
type SupplierUser struct{}
// GetSupplierUser ...
func GetSupplierUser() SupplierUser {
return SupplierUser{}
}
2022-11-02 09:49:12 +00:00
func (s SupplierUser) LoginUser(p model.LoginUserRequest) (*model.LoginUserResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.LoginUser, toBytes(p))
if err != nil {
return nil, err
}
var r struct {
Data *model.LoginUserResponse `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-11-03 03:46:56 +00:00
func (s SupplierUser) GetListUser(p model.GetListUserRequest) (*model.GetListUserResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.GetListUser, toBytes(p))
2022-11-01 03:43:20 +00:00
if err != nil {
return nil, err
}
var r struct {
2022-11-03 03:46:56 +00:00
Data *model.GetListUserResponse `json:"data"`
Error string `json:"error"`
2022-11-01 03:43:20 +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-10-28 02:31:39 +00:00
func (s SupplierUser) CreateSupplierOwnerUsers(p model.CreateOwnerRequest) (*model.CreateOwnerResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateOwner, toBytes(p))
2022-10-25 08:27:05 +00:00
if err != nil {
return nil, err
}
var r struct {
2022-10-28 02:31:39 +00:00
Data *model.CreateOwnerResponse `json:"data"`
Error string `json:"error"`
2022-10-25 08:27:05 +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-10-27 02:09:48 +00:00
2022-10-28 02:31:39 +00:00
func (s SupplierUser) UpdateSupplierOwnerUsers(p model.UpdateOwnerRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateOwner, toBytes(p))
2022-10-27 02:09:48 +00:00
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
}
2022-10-28 02:31:39 +00:00
func (s SupplierUser) CreateSupplierStaffUsers(p model.CreateStaffRequest) (*model.CreateStaffResponse, error) {
msg, err := natsio.GetServer().Request(subject.SupplierUser.CreateStaff, toBytes(p))
2022-10-27 02:09:48 +00:00
if err != nil {
return nil, err
}
var r struct {
2022-10-28 02:31:39 +00:00
Data *model.CreateStaffResponse `json:"data"`
Error string `json:"error"`
2022-10-27 02:09:48 +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-10-28 02:31:39 +00:00
func (s SupplierUser) UpdateSupplierStaffUsers(p model.UpdateStaffRequest) error {
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStaff, toBytes(p))
2022-10-27 02:09:48 +00:00
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
}
2022-10-28 02:31:39 +00:00
func (s SupplierUser) UpdateStatus(p model.UpdateStatusRequest) error {
2022-11-03 03:46:56 +00:00
msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStatus, toBytes(p))
2022-10-28 02:31:39 +00:00
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
}