-
Notifications
You must be signed in to change notification settings - Fork 0
/
put.go
61 lines (52 loc) · 1.27 KB
/
put.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
55
56
57
58
59
60
61
package routers
import (
"net/http"
"github.com/orchestrafm/boards/src/database"
"github.com/spidernest-go/logger"
"github.com/spidernest-go/mux"
)
func updateBoard(c echo.Context) error {
// auth check
admin := HasRole(c, "manage-boards")
auth := HasRole(c, "create-board")
if auth != true {
logger.Info().
Msg("user intent to create a update a board, but was unauthorized.")
return c.JSON(http.StatusUnauthorized, &struct {
Message string
}{
Message: "Insufficient Permissions."})
}
// data binding
b := new(database.Board)
if err := c.Bind(b); err != nil {
logger.Error().
Err(err).
Msg("Request Data could not be binded to datastructure.")
return c.JSON(http.StatusNotAcceptable, &struct {
Message string
}{
Message: "Invalid or malformed board data."})
}
// update resource
if !admin {
return c.JSON(http.StatusUnauthorized, &struct {
Message string
}{
Message: "Not an Administrator."})
}
err := b.Update()
if err != nil {
logger.Error().
Err(err).
Msg("Board could not be updated.")
return c.JSON(http.StatusNotAcceptable, &struct {
Message string
}{
Message: "Invalid or malformed board data."})
}
return c.JSON(http.StatusOK, &struct {
Message string
}{
Message: "Board edited successfully."})
}