-
Notifications
You must be signed in to change notification settings - Fork 0
/
user.go
93 lines (62 loc) · 1.67 KB
/
user.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
85
86
87
88
89
90
91
92
93
package web
import (
"net/http"
"broadcastle.co/code/icii/pkg/ice"
"github.com/labstack/echo"
)
func userCreate(c echo.Context) error {
// Bind the sent data.
user := ice.InitUser()
if err := c.Bind(&user); err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
// Create the user.
if err := ice.New(user); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, user)
}
func userDelete(c echo.Context) error {
user := ice.InitUser()
if err := ice.Echo(c, user); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
if err := ice.Remove(user); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, "user was deleted")
}
func userUpdate(c echo.Context) error {
user := ice.InitUser()
if err := ice.Echo(c, user); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
var new ice.User
if err := c.Bind(&new); err != nil {
return c.JSON(msg(http.StatusInternalServerError, err))
}
if err := ice.Update(user, new); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, user)
}
func userRetrieve(c echo.Context) error {
user := ice.InitUser()
if err := ice.Echo(c, user); err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(http.StatusOK, user)
}
func userLogin(c echo.Context) error {
// Bind the email and password
var user ice.User
if err := c.Bind(&user); err != nil {
return c.JSON(http.StatusInternalServerError, err)
}
// Login
t, err := user.Login()
if err != nil {
return c.JSON(http.StatusMethodNotAllowed, err)
}
return c.JSON(msg(http.StatusOK, t))
}