-
Notifications
You must be signed in to change notification settings - Fork 0
/
station.go
84 lines (55 loc) · 1.62 KB
/
station.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
79
80
81
82
83
84
package web
import (
"net/http"
"broadcastle.co/code/icii/pkg/ice"
"github.com/labstack/echo"
)
func stationCreate(c echo.Context) error {
station := ice.InitStation()
if err := c.Bind(&station); err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
if err := ice.New(station); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
// CLEAN UP
user, err := ice.GetUserFromContext(c)
if err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
if err := user.(*ice.User).CreateStation(*station.(*ice.Station)); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, station)
}
func stationDelete(c echo.Context) error {
station := ice.InitStation()
if err := ice.Echo(c, station); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
if err := ice.Remove(station); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, "sucess")
}
func stationUpdate(c echo.Context) error {
station := ice.InitStation()
if err := ice.Echo(c, station); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
var new ice.Station
if err := c.Bind(&new); err != nil {
return c.JSON(msg(http.StatusInternalServerError, err))
}
if err := ice.Update(station, new); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, station)
}
func stationRetrieve(c echo.Context) error {
station := ice.InitStation()
if err := ice.Echo(c, station); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, station)
}