3
0

upd(system): permission.Get to Read

This commit is contained in:
Mitja Zivkovic
2019-02-22 20:03:01 +01:00
parent 247c7df436
commit 0a517bcd23
7 changed files with 20 additions and 20 deletions

View File

@@ -580,7 +580,7 @@
],
"apis": [
{
"name": "get",
"name": "read",
"path": "/{roleID}/rules",
"method": "GET",
"title": "Retrieve role permissions",

View File

@@ -17,7 +17,7 @@
"Path": "/permissions",
"APIs": [
{
"Name": "get",
"Name": "read",
"Method": "GET",
"Title": "Retrieve role permissions",
"Path": "/{roleID}/rules",

View File

@@ -27,25 +27,25 @@ import (
// Internal API interface
type PermissionAPI interface {
Get(context.Context, *request.PermissionGet) (interface{}, error)
Read(context.Context, *request.PermissionRead) (interface{}, error)
Delete(context.Context, *request.PermissionDelete) (interface{}, error)
Update(context.Context, *request.PermissionUpdate) (interface{}, error)
}
// HTTP API interface
type Permission struct {
Get func(http.ResponseWriter, *http.Request)
Read func(http.ResponseWriter, *http.Request)
Delete func(http.ResponseWriter, *http.Request)
Update func(http.ResponseWriter, *http.Request)
}
func NewPermission(ph PermissionAPI) *Permission {
return &Permission{
Get: func(w http.ResponseWriter, r *http.Request) {
Read: func(w http.ResponseWriter, r *http.Request) {
defer r.Body.Close()
params := request.NewPermissionGet()
params := request.NewPermissionRead()
resputil.JSON(w, params.Fill(r), func() (interface{}, error) {
return ph.Get(r.Context(), params)
return ph.Read(r.Context(), params)
})
},
Delete: func(w http.ResponseWriter, r *http.Request) {
@@ -69,7 +69,7 @@ func (ph *Permission) MountRoutes(r chi.Router, middlewares ...func(http.Handler
r.Group(func(r chi.Router) {
r.Use(middlewares...)
r.Route("/permissions", func(r chi.Router) {
r.Get("/{roleID}/rules", ph.Get)
r.Get("/{roleID}/rules", ph.Read)
r.Delete("/{roleID}/rules", ph.Delete)
r.Patch("/{roleID}/rules", ph.Update)
})

View File

@@ -25,8 +25,8 @@ func (Permission) New() *Permission {
return ctrl
}
func (ctrl *Permission) Get(ctx context.Context, r *request.PermissionGet) (interface{}, error) {
return ctrl.svc.perm.Get(r.RoleID)
func (ctrl *Permission) Read(ctx context.Context, r *request.PermissionRead) (interface{}, error) {
return ctrl.svc.perm.Read(r.RoleID)
}
func (ctrl *Permission) Delete(ctx context.Context, r *request.PermissionDelete) (interface{}, error) {

View File

@@ -31,16 +31,16 @@ import (
var _ = chi.URLParam
var _ = multipart.FileHeader{}
// Permission get request parameters
type PermissionGet struct {
// Permission read request parameters
type PermissionRead struct {
RoleID uint64 `json:",string"`
}
func NewPermissionGet() *PermissionGet {
return &PermissionGet{}
func NewPermissionRead() *PermissionRead {
return &PermissionRead{}
}
func (pe *PermissionGet) Fill(r *http.Request) (err error) {
func (pe *PermissionRead) Fill(r *http.Request) (err error) {
if strings.ToLower(r.Header.Get("content-type")) == "application/json" {
err = json.NewDecoder(r.Body).Decode(pe)
@@ -72,7 +72,7 @@ func (pe *PermissionGet) Fill(r *http.Request) (err error) {
return err
}
var _ RequestFiller = NewPermissionGet()
var _ RequestFiller = NewPermissionRead()
// Permission delete request parameters
type PermissionDelete struct {

View File

@@ -18,7 +18,7 @@ type (
PermissionService interface {
With(ctx context.Context) PermissionService
Get(roleID uint64) (interface{}, error)
Read(roleID uint64) (interface{}, error)
Update(roleID uint64, rules []rules.Rule) (interface{}, error)
Delete(roleID uint64) (interface{}, error)
}
@@ -38,7 +38,7 @@ func (p *permission) With(ctx context.Context) PermissionService {
}
}
func (p *permission) Get(roleID uint64) (interface{}, error) {
func (p *permission) Read(roleID uint64) (interface{}, error) {
return p.resources.List(roleID)
}

View File

@@ -93,7 +93,7 @@ func TestPermission(t *testing.T) {
// List rules for test role.
{
ret, err := permissionSvc.Get(role.ID)
ret, err := permissionSvc.Read(role.ID)
NoError(t, err, "expected no error, setting rules")
rules := ret.([]rules.Rule)
@@ -109,7 +109,7 @@ func TestPermission(t *testing.T) {
// List rules for test role.
{
ret, err := permissionSvc.Get(role.ID)
ret, err := permissionSvc.Read(role.ID)
NoError(t, err, "expected no error, setting rules")
rules := ret.([]rules.Rule)