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) Logout(p model.LogoutRequest) error { msg, err := natsio.GetServer().Request(subject.SupplierUser.Logout, 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) GetListUser(p model.GetListUserRequest) (*model.GetListUserResponse, error) { msg, err := natsio.GetServer().Request(subject.SupplierUser.GetListUser, toBytes(p)) if err != nil { return nil, err } var r struct { Data *model.GetListUserResponse `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) DetailUser(p model.DetailUserRequest) (*model.SupplierUserBrief, error) { msg, err := natsio.GetServer().Request(subject.SupplierUser.DetailUser, toBytes(p)) if err != nil { return nil, err } var r struct { Data *model.SupplierUserBrief `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.UpdateStatus, 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 } func (s SupplierUser) ChangePassword(p model.ChangePasswordRequest) error { msg, err := natsio.GetServer().Request(subject.SupplierUser.UpdateStatus, 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 } // 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 }