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" ) // SupplierRole ... type SupplierRole struct{} // GetSupplierRole ... func GetSupplierRole() SupplierRole { return SupplierRole{} } func (s SupplierRole) GetListRole(p model.GetListRoleRequest) (*model.GetListRoleResponse, error) { msg, err := natsio.GetServer().Request(subject.SupplierRole.GetList, toBytes(p)) if err != nil { return nil, err } var r struct { Data *model.GetListRoleResponse `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 SupplierRole) CreateRole(p model.CreateRoleRequest) (*model.CreateRoleResponse, error) { msg, err := natsio.GetServer().Request(subject.SupplierRole.Create, toBytes(p)) if err != nil { return nil, err } var r struct { Data *model.CreateRoleResponse `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 SupplierRole) UpdateRole(p model.UpdateRoleRequest) error { msg, err := natsio.GetServer().Request(subject.SupplierRole.Update, 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 SupplierRole) DetailRole(p model.DetailRoleRequest) (*model.RoleBrief, error) { msg, err := natsio.GetServer().Request(subject.SupplierRole.Detail, toBytes(p)) if err != nil { return nil, err } var r struct { Data *model.RoleBrief `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 }