权限初步模板

This commit is contained in:
pixelqm
2019-09-08 16:37:05 +08:00
parent 1b1ceefa27
commit 9f17f71ee2
13 changed files with 707 additions and 101 deletions

View File

@@ -0,0 +1,56 @@
package api
import (
"fmt"
"github.com/gin-gonic/gin"
"main/controller/servers"
"main/model/dbModel"
)
type CreateApiParams struct {
AuthorityId uint `json:"-"`
Path string `json:"path"`
Description string `json:"description"`
}
type DeleteApiParams struct {
AuthorityId uint `json:"-"`
}
// @Tags Api
// @Summary 为指定角色创建api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.CreateApiParams true "创建api"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/createApi [post]
func CreateApi(c *gin.Context) {
var api dbModel.Api
_ = c.BindJSON(&api)
err := api.CreateApi()
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "创建成功", gin.H{})
}
}
// @Tags Api
// @Summary 删除指定角色api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.DeleteApiParams true "删除api"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/deleteApi [post]
func DeleteApi(c *gin.Context) {
var a dbModel.Api
_ = c.BindJSON(&a)
err := a.DeleteApi()
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "删除成功", gin.H{})
}
}

View File

@@ -0,0 +1,60 @@
package api
import (
"fmt"
"github.com/gin-gonic/gin"
"main/controller/servers"
"main/model/dbModel"
)
type CreateAuthorityPatams struct {
AuthorityId uint `json:"authorityId"`
AuthorityName string `json:"authorityName"`
}
// @Tags authority
// @Summary 创建角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.CreateAuthorityPatams true "创建角色"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /authority/createAuthority [post]
func CreateAuthority(c *gin.Context) {
var auth dbModel.Authority
_ = c.BindJSON(&auth)
err, authBack := auth.CreateAuthority()
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{
"authority": authBack,
})
} else {
servers.ReportFormat(c, true, "创建成功", gin.H{
"authority": authBack,
})
}
}
type DeleteAuthorityPatams struct {
AuthorityId uint `json:"authorityId"`
}
// @Tags authority
// @Summary 删除角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.DeleteAuthorityPatams true "删除角色"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /authority/deleteAuthority [post]
func DeleteAuthority(c *gin.Context) {
var a dbModel.Authority
_ = c.BindJSON(&a)
//删除角色之前需要判断是否有用户正在使用此角色
err := a.DeleteAuthority()
if err != nil {
servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
} else {
servers.ReportFormat(c, true, "删除成功", gin.H{})
}
}

View File

@@ -15,6 +15,7 @@ import (
// @Param data body api.RegistAndLoginStuct true "可以什么都不填"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"返回成功"}"
// @Router /menu/getMenu [post]
func GetMenu(c *gin.Context) {
claims, _ := c.Get("claims")
waitUse := claims.(*middleware.CustomClaims)