-
Notifications
You must be signed in to change notification settings - Fork 180
/
resourceController.go
247 lines (225 loc) · 5.74 KB
/
resourceController.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
package controllers
import (
"github.com/astaxie/beego/context"
"github.com/hzwy23/hauth/core/groupcache"
"github.com/hzwy23/hauth/core/hrpc"
"github.com/hzwy23/hauth/core/models"
"github.com/hzwy23/hauth/utils/hret"
"github.com/hzwy23/hauth/utils/i18n"
"github.com/hzwy23/hauth/utils/logs"
)
type resourceController struct {
models *models.ResourceModel
}
var ResourceCtl = &resourceController{
new(models.ResourceModel),
}
// swagger:operation GET /v1/auth/resource/page StaticFiles domainShareControll
//
// 返回菜单资源管理页面
//
// 系统会对请求用户权限进行校验,校验通过,将会返回菜单管理配置页面.
// ---
// produces:
// - application/json
// - application/xml
// - text/xml
// - text/html
// parameters:
// responses:
// '200':
// description: all domain information
func (resourceController) Page(ctx *context.Context) {
ctx.Request.ParseForm()
if !hrpc.BasicAuth(ctx.Request) {
hret.Error(ctx.ResponseWriter, 403, i18n.NoAuth(ctx.Request))
return
}
rst, err := groupcache.GetStaticFile("AsofdateResourcePage")
if err != nil {
hret.Error(ctx.ResponseWriter, 404, i18n.PageNotFound(ctx.Request))
return
}
ctx.ResponseWriter.Write(rst)
}
// swagger:operation GET /v1/auth/resource/get resourceController getdomainShareControll
//
// 返回系统中所有的菜单资源信息
//
// 系统会对用户权限进行校验,校验通过,将会返回菜单资源信息
//
// ---
// produces:
// - application/json
// - application/xml
// - text/xml
// - text/html
// parameters:
// - name: domain_id
// in: query
// description: domain code number
// required: true
// type: string
// format:
// responses:
// '200':
// description: success
func (this resourceController) Get(ctx *context.Context) {
ctx.Request.ParseForm()
if !hrpc.BasicAuth(ctx.Request) {
hret.Error(ctx.ResponseWriter, 403, i18n.NoAuth(ctx.Request))
return
}
rst, err := this.models.Get()
if err != nil {
logs.Error(err)
hret.Error(ctx.ResponseWriter, 419, i18n.Get(ctx.Request, "error_resource_query"), err)
return
}
hret.Json(ctx.ResponseWriter, rst)
}
// swagger:operation GET /v1/auth/resource/query resourceController getdomainShareControll
//
// 查询指定菜单的详细信息
//
// 查询某个指定资源的详细信息
// ---
// produces:
// - application/json
// - application/xml
// - text/xml
// - text/html
// parameters:
// - name: res_id
// in: query
// description: resource code number
// required: true
// type: string
// format:
// responses:
// '200':
// description: success
func (this resourceController) Query(ctx *context.Context) {
ctx.Request.ParseForm()
res_id := ctx.Request.FormValue("res_id")
rst, err := this.models.Query(res_id)
if err != nil {
logs.Error(err)
hret.Error(ctx.ResponseWriter, 419, i18n.Get(ctx.Request, "error_resource_query"), err)
return
}
hret.Json(ctx.ResponseWriter, rst)
}
// swagger:operation POST /v1/auth/resource/post resourceController getdomainShareControll
//
// 新增菜单信息
//
// 向系统中新增菜单资源信息
// ---
// produces:
// - application/json
// - application/xml
// - text/xml
// - text/html
// parameters:
// responses:
// '200':
// description: success
func (this resourceController) Post(ctx *context.Context) {
ctx.Request.ParseForm()
if !hrpc.BasicAuth(ctx.Request) {
hret.Error(ctx.ResponseWriter, 403, i18n.NoAuth(ctx.Request))
return
}
form := ctx.Request.Form
msg, err := this.models.Post(form)
if err != nil {
logs.Error(err)
hret.Error(ctx.ResponseWriter, 421, i18n.Get(ctx.Request, msg), err)
return
}
hret.Success(ctx.ResponseWriter, i18n.Success(ctx.Request))
}
// swagger:operation POST /v1/auth/resource/delete resourceController getdomainShareControll
//
// 删除菜单信息
//
// 删除系统中的菜单资源信息,系统会对用户的权限进行校验,只有校验通过,才能删除菜单资源信息.
// ---
// produces:
// - application/json
// - application/xml
// - text/xml
// - text/html
// parameters:
// - name: res_id
// in: query
// description: resource code number
// required: true
// type: string
// format:
// responses:
// '200':
// description: success
func (this resourceController) Delete(ctx *context.Context) {
ctx.Request.ParseForm()
if !hrpc.BasicAuth(ctx.Request) {
hret.Error(ctx.ResponseWriter, 403, i18n.NoAuth(ctx.Request))
return
}
res_id := ctx.Request.FormValue("res_id")
msg, err := this.models.Delete(res_id)
if err != nil {
logs.Error(err)
hret.Error(ctx.ResponseWriter, 419, msg, err)
return
}
hret.Success(ctx.ResponseWriter, i18n.Success(ctx.Request))
}
// swagger:operation PUT /v1/auth/resource/update resourceController getdomainShareControll
//
// 更新菜单信息
//
// API只支持修改菜单的名称
//
// ---
// produces:
// - application/json
// - application/xml
// - text/xml
// - text/html
// parameters:
// - name: res_id
// in: query
// description: resource code number
// required: true
// type: string
// format:
// - name: res_name
// in: query
// description: resource describe
// required: true
// type: string
// format:
// responses:
// '200':
// description: success
func (this resourceController) Update(ctx *context.Context) {
ctx.Request.ParseForm()
if !hrpc.BasicAuth(ctx.Request) {
hret.Error(ctx.ResponseWriter, 403, i18n.NoAuth(ctx.Request))
return
}
res_id := ctx.Request.FormValue("res_id")
res_name := ctx.Request.FormValue("res_name")
msg, err := this.models.Update(res_id, res_name)
if err != nil {
logs.Error(err)
hret.Error(ctx.ResponseWriter, 421, i18n.Get(ctx.Request, msg), err)
return
}
hret.Success(ctx.ResponseWriter, i18n.Success(ctx.Request))
}
func init() {
groupcache.RegisterStaticFile("AsofdateResourcePage", "./views/hauth/res_info_page.tpl")
}