权限管理完成

This commit is contained in:
pixel
2019-09-30 15:46:13 +08:00
parent d46f7e1f75
commit 509b6e18e1
15 changed files with 272 additions and 65 deletions

View File

@@ -57,7 +57,7 @@ func DeleteApi(c *gin.Context) {
type AuthAndPathIn struct {
AuthorityId string `json:"authorityId"`
Apis []dbModel.Api `json:"apis"`
ApiIds []uint `json:"apiIds"`
}
// @Tags Api
@@ -71,7 +71,7 @@ type AuthAndPathIn struct {
func SetAuthAndApi(c *gin.Context) {
var authAndPathIn AuthAndPathIn
_ = c.BindJSON(&authAndPathIn)
err := new(dbModel.ApiAuthority).SetAuthAndApi(authAndPathIn.AuthorityId, authAndPathIn.Apis)
err := new(dbModel.ApiAuthority).SetAuthAndApi(authAndPathIn.AuthorityId, authAndPathIn.ApiIds)
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("添加失败:%v", err), gin.H{})
} else {
@@ -136,7 +136,6 @@ func GetApiById(c *gin.Context) {
// @Param data body api.CreateApiParams true "创建api"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/updataApi [post]
func UpdataApi(c *gin.Context) {
var api dbModel.Api
_ = c.BindJSON(&api)
@@ -146,4 +145,22 @@ func GetApiById(c *gin.Context) {
} else {
servers.ReportFormat(c, true, "修改数据成功", gin.H{})
}
}
}
// @Tags Api
// @Summary 获取所有的Api 不分页
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/getAllApis [post]
func GetAllApis(c *gin.Context){
err,apis := new(dbModel.Api).GetAllApis()
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "获取数据成功", gin.H{
"apis": apis,
})
}
}

View File

@@ -82,4 +82,30 @@ func GetAuthorityList(c *gin.Context){
"pageSize": pageInfo.PageSize,
})
}
}
type GetAuthorityId struct {
AuthorityId string `json:"authorityId"`
}
// @Tags authority
// @Summary 获取本角色所有有权限的apiId
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.GetAuthorityId true "获取本角色所有有权限的apiId"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /authority/getAuthAndApi [post]
func GetAuthAndApi(c *gin.Context){
var idInfo GetAuthorityId
_ = c.BindJSON(&idInfo)
err,apis := new(dbModel.ApiAuthority).GetAuthAndApi(idInfo.AuthorityId)
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "获取数据成功", gin.H{
"apis": apis,
})
}
}

View File

@@ -138,7 +138,7 @@ type IdInfo struct {
}
// @Tags menu
// @Summary 获取指定角色menu
// @Summary 删除菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
@@ -157,11 +157,11 @@ func DeleteBaseMenu(c *gin.Context) {
}
// @Tags menu
// @Summary 新菜单
// @Summary 新菜单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body dbModel.BaseMenu true "新菜单"
// @Param data body dbModel.BaseMenu true "新菜单"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /menu/updataBaseMen [post]
func UpdataBaseMenu(c *gin.Context) {