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) 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 } func (s SupplierUser) GetListOwner(p model.GetListOwnerRequest) (*model.GetListOwnerResponse, error) { msg, err := natsio.GetServer().Request(subject.SupplierUser.GetListOwner, toBytes(p)) if err != nil { return nil, err } var r struct { Data *model.GetListOwnerResponse `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) 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 }