-
Notifications
You must be signed in to change notification settings - Fork 0
/
get.go
78 lines (63 loc) · 1.73 KB
/
get.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package routers
import (
"net/http"
"strconv"
"github.com/orchestrafm/scores/src/database"
"github.com/spidernest-go/logger"
"github.com/spidernest-go/mux"
)
func getScore(c echo.Context) error {
i, err := strconv.ParseUint(c.Param("id"), 10, 64)
if err != nil {
logger.Error().
Err(err).
Msgf("Passed id parameter (%s) was not a valid number", c.Param("id"))
return c.JSON(http.StatusBadRequest, nil)
}
s, err := database.SelectID(i)
if err != nil {
logger.Error().
Err(err).
Msg(".")
c.JSON(http.StatusNotFound, ErrGeneric)
}
return c.JSON(http.StatusOK, s)
}
func getScoresFromBoard(c echo.Context) error {
t, err := strconv.ParseUint(c.QueryParam("track"), 10, 64)
if err != nil {
logger.Error().
Err(err).
Msgf("Passed track parameter (%s) was not a valid number", c.QueryParam("track"))
return c.JSON(http.StatusBadRequest, nil)
}
b, err := strconv.ParseUint(c.QueryParam("board"), 10, 64)
if err != nil {
logger.Error().
Err(err).
Msgf("Passed board parameter (%s) was not a valid number", c.QueryParam("board"))
return c.JSON(http.StatusBadRequest, nil)
}
l, err := strconv.Atoi(c.QueryParam("limit"))
if err != nil {
logger.Error().
Err(err).
Msgf("Passed limit parameter (%s) was not a valid number", c.QueryParam("limit"))
return c.JSON(http.StatusBadRequest, nil)
}
o, err := strconv.Atoi(c.QueryParam("offset"))
if err != nil {
logger.Error().
Err(err).
Msgf("Passed offset parameter (%s) was not a valid number", c.QueryParam("offset"))
return c.JSON(http.StatusBadRequest, nil)
}
ss, err := database.SelectOrdinally(t, b, l, o)
if err != nil {
logger.Error().
Err(err).
Msg(".")
c.JSON(http.StatusNotFound, ss)
}
return c.JSON(http.StatusOK, ss)
}