-
Notifications
You must be signed in to change notification settings - Fork 1
/
roles.go
54 lines (45 loc) · 1.49 KB
/
roles.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
package controllers
import (
"github.com/ernestio/api-gateway/controllers/roles"
h "github.com/ernestio/api-gateway/helpers"
"github.com/labstack/echo"
)
// GetRolesHandler : responds to GET /roles/ with a list of all
// roles for admin, and all roles in your group for other
// roles
func GetRolesHandler(c echo.Context) error {
return genericList(c, "role", roles.List)
}
// GetRoleHandler : responds to GET /roles/:role/ with the role
// details
func GetRoleHandler(c echo.Context) error {
return genericGet(c, "role", roles.Get)
}
// CreateRoleHandler : responds to POST /roles/ by creating a
// role on the data store
func CreateRoleHandler(c echo.Context) (err error) {
return genericCreate(c, "role", roles.Create)
}
// DeleteRoleByIDHandler : responds to DELETE /roles/:id: by deleting an
// existing role
func DeleteRoleByIDHandler(c echo.Context) error {
return genericDelete(c, "role", roles.DeleteByID)
}
// DeleteRoleHandler : responds to DELETE /roles/:id: by deleting an
// existing role
func DeleteRoleHandler(c echo.Context) error {
au := AuthenticatedUser(c)
st, b := h.IsAuthorized(&au, "roles/delete")
if st == 200 {
st = 500
b = []byte("Invalid input")
body, err := h.GetRequestBody(c)
if err == nil {
st, b = roles.Delete(au, body)
}
}
return h.Respond(c, st, b)
}