sys_authority.go 2.8 KB
Newer Older
Mr.奇淼('s avatar
Mr.奇淼( 已提交
1
package v1
Mr.奇淼('s avatar
Mr.奇淼( 已提交
2 3 4

import (
	"fmt"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
5 6
	"gin-vue-admin/global/response"
	"gin-vue-admin/model"
7
	"gin-vue-admin/model/request"
8
	resp "gin-vue-admin/model/response"
9
	"gin-vue-admin/service"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
10 11 12 13 14 15 16 17
	"github.com/gin-gonic/gin"
)

// @Tags authority
// @Summary 创建角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
18
// @Param data body model.SysAuthority true "创建角色"
19
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
20 21
// @Router /authority/createAuthority [post]
func CreateAuthority(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
22
	var auth model.SysAuthority
23
	_ = c.ShouldBindJSON(&auth)
24
	err, authBack := service.CreateAuthority(auth)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
25
	if err != nil {
26
		response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
27
	} else {
28
		response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
29 30 31 32 33 34 35 36
	}
}

// @Tags authority
// @Summary 删除角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
37
// @Param data body model.SysAuthority true "删除角色"
38
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
Mr.奇淼('s avatar
Mr.奇淼( 已提交
39 40
// @Router /authority/deleteAuthority [post]
func DeleteAuthority(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
41
	var a model.SysAuthority
42
	_ = c.ShouldBindJSON(&a)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
43
	//删除角色之前需要判断是否有用户正在使用此角色
44
	err := service.DeleteAuthority(&a)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
45
	if err != nil {
46
		response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
47
	} else {
48
		response.OkWithMessage("删除成功", c)
Mr.奇淼('s avatar
Mr.奇淼( 已提交
49 50
	}
}
51 52 53 54 55 56

// @Tags authority
// @Summary 分页获取角色列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
Mr.奇淼('s avatar
Mr.奇淼( 已提交
57
// @Param data body model.PageInfo true "分页获取用户列表"
58
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
59
// @Router /authority/getAuthorityList [post]
60
func GetAuthorityList(c *gin.Context) {
61
	var pageInfo request.PageInfo
62
	_ = c.ShouldBindJSON(&pageInfo)
63
	err, list, total := service.GetAuthorityInfoList(pageInfo)
64
	if err != nil {
65
		response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
66
	} else {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
67 68 69 70 71 72
		response.OkWithData(resp.PageResult{
			List:     list,
			Total:    total,
			Page:     pageInfo.Page,
			PageSize: pageInfo.PageSize,
		}, c)
73
	}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
74 75
}

76 77 78 79 80
// @Tags authority
// @Summary 设置角色资源权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
81
// @Param data body model.SysAuthority true "设置角色资源权限"
82 83 84
// @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
// @Router /authority/setDataAuthority [post]
func SetDataAuthority(c *gin.Context) {
Mr.奇淼('s avatar
Mr.奇淼( 已提交
85
	var auth model.SysAuthority
86
	_ = c.ShouldBindJSON(&auth)
87
	err := service.SetDataAuthority(auth)
88
	if err != nil {
89
		response.FailWithMessage(fmt.Sprintf("设置关联失败,%v", err), c)
90
	} else {
91
		response.Ok(c)
92
	}
Mr.奇淼('s avatar
Mr.奇淼( 已提交
93
}