Skip to content

Commit 211b1f2

Browse files
author
pixel
committed
后台格式规范化 引入casbin做鉴权
1 parent 718c6e6 commit 211b1f2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+576
-338
lines changed

QMPlusServer/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ var Dbconfig Config
2222
func init() {
2323
v := viper.New()
2424
v.SetConfigName("config") // 设置配置文件名 (不带后缀)
25-
v.AddConfigPath("./config/dbconfig/") // 第一个搜索路径
25+
v.AddConfigPath("./static/dbconfig/") // 第一个搜索路径
2626
v.SetConfigType("json")
2727
err := v.ReadInConfig() // 搜索路径,并读取配置数据
2828
if err != nil {

QMPlusServer/controller/api/fileUploadAndDownload.go renamed to QMPlusServer/controller/api/exa_fileUploadAndDownload.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"strings"
1010
)
1111

12-
// @Tags FileUploadAndDownload
12+
// @Tags ExaFileUploadAndDownload
1313
// @Summary 上传文件示例
1414
// @Security ApiKeyAuth
1515
// @accept multipart/form-data
@@ -28,7 +28,7 @@ func UploadFile(c *gin.Context) {
2828
servers.ReportFormat(c, false, fmt.Sprintf("接收返回值失败,%v", err), gin.H{})
2929
} else {
3030
//修改数据库后得到修改后的user并且返回供前端使用
31-
var file dbModel.FileUploadAndDownload
31+
var file dbModel.ExaFileUploadAndDownload
3232
file.Url = filePath
3333
file.Name = header.Filename
3434
s := strings.Split(file.Name, ".")
@@ -44,15 +44,15 @@ func UploadFile(c *gin.Context) {
4444
}
4545
}
4646

47-
// @Tags FileUploadAndDownload
47+
// @Tags ExaFileUploadAndDownload
4848
// @Summary 删除文件
4949
// @Security ApiKeyAuth
5050
// @Produce application/json
51-
// @Param data body dbModel.FileUploadAndDownload true "传入文件里面id即可"
51+
// @Param data body dbModel.ExaFileUploadAndDownload true "传入文件里面id即可"
5252
// @Success 200 {string} json "{"success":true,"data":{},"msg":"返回成功"}"
5353
// @Router /fileUploadAndDownload/deleteFile [post]
5454
func DeleteFile(c *gin.Context) {
55-
var file dbModel.FileUploadAndDownload
55+
var file dbModel.ExaFileUploadAndDownload
5656
_ = c.ShouldBind(&file)
5757
err, f := file.FindFile()
5858
if err != nil {
@@ -72,7 +72,7 @@ func DeleteFile(c *gin.Context) {
7272
}
7373
}
7474

75-
// @Tags FileUploadAndDownload
75+
// @Tags ExaFileUploadAndDownload
7676
// @Summary 分页文件列表
7777
// @Security ApiKeyAuth
7878
// @accept application/json
@@ -83,7 +83,7 @@ func DeleteFile(c *gin.Context) {
8383
func GetFileList(c *gin.Context) {
8484
var pageInfo modelInterface.PageInfo
8585
_ = c.BindJSON(&pageInfo)
86-
err, list, total := new(dbModel.FileUploadAndDownload).GetInfoList(pageInfo)
86+
err, list, total := new(dbModel.ExaFileUploadAndDownload).GetInfoList(pageInfo)
8787
if err != nil {
8888
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
8989
} else {

QMPlusServer/controller/api/api.go renamed to QMPlusServer/controller/api/sys_api.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"github.com/gin-gonic/gin"
66
"main/controller/servers"
7-
"main/model/dbModel"
87
"main/model/modelInterface"
8+
"main/model/sysModel"
99
)
1010

1111
type CreateApiParams struct {
@@ -17,7 +17,7 @@ type DeleteApiParams struct {
1717
ID uint `json:"id"`
1818
}
1919

20-
// @Tags Api
20+
// @Tags SysApi
2121
// @Summary 创建基础api
2222
// @Security ApiKeyAuth
2323
// @accept application/json
@@ -26,7 +26,7 @@ type DeleteApiParams struct {
2626
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
2727
// @Router /api/createApi [post]
2828
func CreateApi(c *gin.Context) {
29-
var api dbModel.Api
29+
var api sysModel.SysApi
3030
_ = c.BindJSON(&api)
3131
err := api.CreateApi()
3232
if err != nil {
@@ -36,16 +36,16 @@ func CreateApi(c *gin.Context) {
3636
}
3737
}
3838

39-
// @Tags Api
39+
// @Tags SysApi
4040
// @Summary 删除指定api
4141
// @Security ApiKeyAuth
4242
// @accept application/json
4343
// @Produce application/json
44-
// @Param data body dbModel.Api true "删除api"
44+
// @Param data body sysModel.SysApi true "删除api"
4545
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
4646
// @Router /api/deleteApi [post]
4747
func DeleteApi(c *gin.Context) {
48-
var a dbModel.Api
48+
var a sysModel.SysApi
4949
_ = c.BindJSON(&a)
5050
err := a.DeleteApi()
5151
if err != nil {
@@ -60,7 +60,7 @@ type AuthAndPathIn struct {
6060
ApiIds []uint `json:"apiIds"`
6161
}
6262

63-
// @Tags Api
63+
// @Tags SysApi
6464
// @Summary 创建api和角色关系
6565
// @Security ApiKeyAuth
6666
// @accept application/json
@@ -71,7 +71,7 @@ type AuthAndPathIn struct {
7171
func SetAuthAndApi(c *gin.Context) {
7272
var authAndPathIn AuthAndPathIn
7373
_ = c.BindJSON(&authAndPathIn)
74-
err := new(dbModel.ApiAuthority).SetAuthAndApi(authAndPathIn.AuthorityId, authAndPathIn.ApiIds)
74+
err := new(sysModel.SysApiAuthority).SetAuthAndApi(authAndPathIn.AuthorityId, authAndPathIn.ApiIds)
7575
if err != nil {
7676
servers.ReportFormat(c, false, fmt.Sprintf("添加失败:%v", err), gin.H{})
7777
} else {
@@ -81,7 +81,7 @@ func SetAuthAndApi(c *gin.Context) {
8181

8282
//条件搜索后端看此api
8383

84-
// @Tags Api
84+
// @Tags SysApi
8585
// @Summary 分页获取API列表
8686
// @Security ApiKeyAuth
8787
// @accept application/json
@@ -92,12 +92,12 @@ func SetAuthAndApi(c *gin.Context) {
9292
func GetApiList(c *gin.Context) {
9393
// 此结构体仅本方法使用
9494
type searchParams struct {
95-
dbModel.Api
95+
sysModel.SysApi
9696
modelInterface.PageInfo
9797
}
9898
var sp searchParams
9999
_ = c.ShouldBindJSON(&sp)
100-
err, list, total := sp.Api.GetInfoList(sp.PageInfo)
100+
err, list, total := sp.SysApi.GetInfoList(sp.PageInfo)
101101
if err != nil {
102102
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
103103
} else {
@@ -111,7 +111,7 @@ func GetApiList(c *gin.Context) {
111111
}
112112
}
113113

114-
// @Tags Api
114+
// @Tags SysApi
115115
// @Summary 根据id获取api
116116
// @Security ApiKeyAuth
117117
// @accept application/json
@@ -122,7 +122,7 @@ func GetApiList(c *gin.Context) {
122122
func GetApiById(c *gin.Context) {
123123
var idInfo GetById
124124
_ = c.BindJSON(&idInfo)
125-
err, api := new(dbModel.Api).GetApiById(idInfo.Id)
125+
err, api := new(sysModel.SysApi).GetApiById(idInfo.Id)
126126
if err != nil {
127127
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
128128
} else {
@@ -133,7 +133,7 @@ func GetApiById(c *gin.Context) {
133133
}
134134
}
135135

136-
// @Tags Api
136+
// @Tags SysApi
137137
// @Summary 创建基础api
138138
// @Security ApiKeyAuth
139139
// @accept application/json
@@ -142,7 +142,7 @@ func GetApiById(c *gin.Context) {
142142
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
143143
// @Router /api/updataApi [post]
144144
func UpdataApi(c *gin.Context) {
145-
var api dbModel.Api
145+
var api sysModel.SysApi
146146
_ = c.BindJSON(&api)
147147
err := api.UpdataApi()
148148
if err != nil {
@@ -152,15 +152,15 @@ func UpdataApi(c *gin.Context) {
152152
}
153153
}
154154

155-
// @Tags Api
155+
// @Tags SysApi
156156
// @Summary 获取所有的Api 不分页
157157
// @Security ApiKeyAuth
158158
// @accept application/json
159159
// @Produce application/json
160160
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
161161
// @Router /api/getAllApis [post]
162162
func GetAllApis(c *gin.Context) {
163-
err, apis := new(dbModel.Api).GetAllApis()
163+
err, apis := new(sysModel.SysApi).GetAllApis()
164164
if err != nil {
165165
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
166166
} else {

QMPlusServer/controller/api/authority.go renamed to QMPlusServer/controller/api/sys_authority.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"github.com/gin-gonic/gin"
66
"main/controller/servers"
7-
"main/model/dbModel"
87
"main/model/modelInterface"
8+
"main/model/sysModel"
99
)
1010

1111
type CreateAuthorityPatams struct {
@@ -22,7 +22,7 @@ type CreateAuthorityPatams struct {
2222
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
2323
// @Router /authority/createAuthority [post]
2424
func CreateAuthority(c *gin.Context) {
25-
var auth dbModel.Authority
25+
var auth sysModel.SysAuthority
2626
_ = c.ShouldBind(&auth)
2727
err, authBack := auth.CreateAuthority()
2828
if err != nil {
@@ -49,7 +49,7 @@ type DeleteAuthorityPatams struct {
4949
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
5050
// @Router /authority/deleteAuthority [post]
5151
func DeleteAuthority(c *gin.Context) {
52-
var a dbModel.Authority
52+
var a sysModel.SysAuthority
5353
_ = c.BindJSON(&a)
5454
//删除角色之前需要判断是否有用户正在使用此角色
5555
err := a.DeleteAuthority()
@@ -71,7 +71,7 @@ func DeleteAuthority(c *gin.Context) {
7171
func GetAuthorityList(c *gin.Context){
7272
var pageInfo modelInterface.PageInfo
7373
_ = c.BindJSON(&pageInfo)
74-
err, list, total := new(dbModel.Authority).GetInfoList(pageInfo)
74+
err, list, total := new(sysModel.SysAuthority).GetInfoList(pageInfo)
7575
if err != nil {
7676
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
7777
} else {
@@ -100,7 +100,7 @@ type GetAuthorityId struct {
100100
func GetAuthAndApi(c *gin.Context){
101101
var idInfo GetAuthorityId
102102
_ = c.BindJSON(&idInfo)
103-
err,apis := new(dbModel.ApiAuthority).GetAuthAndApi(idInfo.AuthorityId)
103+
err,apis := new(sysModel.SysApiAuthority).GetAuthAndApi(idInfo.AuthorityId)
104104
if err != nil {
105105
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
106106
} else {
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package api
2+
3+
import (
4+
"fmt"
5+
"github.com/gin-gonic/gin"
6+
"main/controller/servers"
7+
"main/model/sysModel"
8+
)
9+
10+
11+
type CasbinInReceive struct {
12+
AuthorityId string `json:"authorityId"`
13+
Paths []string `json:paths`
14+
}
15+
16+
// @Tags casbin
17+
// @Summary 更改角色api权限
18+
// @Security ApiKeyAuth
19+
// @accept application/json
20+
// @Produce application/json
21+
// @Param data body api.CreateAuthorityPatams true "更改角色api权限"
22+
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
23+
// @Router /casbin/casbinPUpdata [post]
24+
func CasbinPUpdata(c *gin.Context){
25+
var cmr CasbinInReceive
26+
_ = c.ShouldBind(&cmr)
27+
err := new(sysModel.CasbinModel).CasbinPUpdata(cmr.AuthorityId,cmr.Paths)
28+
if err != nil {
29+
servers.ReportFormat(c, false, fmt.Sprintf("添加规则失败,%v", err), gin.H{})
30+
} else {
31+
servers.ReportFormat(c, true, "添加规则成功", gin.H{})
32+
}
33+
}
34+
35+
// @Tags casbin
36+
// @Summary 获取权限列表
37+
// @Security ApiKeyAuth
38+
// @accept application/json
39+
// @Produce application/json
40+
// @Param data body api.CreateAuthorityPatams true "获取权限列表"
41+
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
42+
// @Router /casbin/getPolicyPathByAuthorityId [post]
43+
func GetPolicyPathByAuthorityId(c *gin.Context){
44+
var cmr CasbinInReceive
45+
_ = c.ShouldBind(&cmr)
46+
paths := new(sysModel.CasbinModel).GetPolicyPathByAuthorityId(cmr.AuthorityId)
47+
servers.ReportFormat(c, true, "获取规则成功", gin.H{"paths":paths})
48+
}

0 commit comments

Comments
 (0)