-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.go
54 lines (46 loc) · 1.08 KB
/
delete.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
package routers
import (
"net/http"
"strconv"
"github.com/orchestrafm/scores/src/database"
"github.com/spidernest-go/logger"
"github.com/spidernest-go/mux"
)
func deleteScore(c echo.Context) error {
// auth check
admin := HasRole(c, "manage-scores")
if admin != true {
logger.Info().
Msg("user intent to create a delete a score, but was unauthorized.")
return c.JSON(http.StatusUnauthorized, &struct {
Message string
}{
Message: "Insufficient Permissions."})
}
// search for score
i, err := strconv.ParseUint(c.Param("id"), 10, 64)
if err != nil {
logger.Error().
Err(err).
Msg("Invalid Parameters for deleting a score.")
return c.JSON(http.StatusNotAcceptable, &struct {
Message string
}{
Message: "."})
}
// remove score
err = database.Remove(i)
if err != nil {
logger.Error().
Err(err).
Msg("Invalid Parameters for deleting a score.")
return c.JSON(http.StatusNotAcceptable, &struct {
Message string
}{
Message: "."})
}
return c.JSON(http.StatusOK, &struct {
Message string
}{
Message: "Score deleted successfully."})
}