This repository has been archived by the owner on Jul 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 38
/
handler_users.go
81 lines (75 loc) · 1.51 KB
/
handler_users.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
package handlers
import (
"github.com/dejavuzhou/ginbro/boilerplate/models"
"github.com/gin-gonic/gin"
)
func init() {
groupApi.GET("user", jwtMiddleware, userAll)
groupApi.GET("user/:id", jwtMiddleware, userOne)
groupApi.POST("user", jwtMiddleware, userCreate)
groupApi.PATCH("user", jwtMiddleware, userUpdate)
groupApi.DELETE("user/:id", jwtMiddleware, userDelete)
}
func userAll(c *gin.Context) {
mdl := models.AuthorizationModel{}
query := &models.PaginationQuery{}
err := c.ShouldBindQuery(query)
if handleError(c, err) {
return
}
list, total, err := mdl.All(query)
if handleError(c, err) {
return
}
jsonPagination(c, list, total, query)
}
func userOne(c *gin.Context) {
var mdl models.AuthorizationModel
id, err := parseParamID(c)
if handleError(c, err) {
return
}
mdl.Id = id
data, err := mdl.One()
if handleError(c, err) {
return
}
jsonData(c, data)
}
func userCreate(c *gin.Context) {
var mdl models.AuthorizationModel
err := c.ShouldBind(&mdl)
if handleError(c, err) {
return
}
err = mdl.Create()
if handleError(c, err) {
return
}
jsonData(c, mdl)
}
func userUpdate(c *gin.Context) {
var mdl models.AuthorizationModel
err := c.ShouldBind(&mdl)
if handleError(c, err) {
return
}
err = mdl.Update()
if handleError(c, err) {
return
}
jsonSuccess(c)
}
func userDelete(c *gin.Context) {
var mdl models.AuthorizationModel
id, err := parseParamID(c)
if handleError(c, err) {
return
}
mdl.Id = id
err = mdl.Delete()
if handleError(c, err) {
return
}
jsonSuccess(c)
}