sys_authority.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. package v1
  2. import (
  3. "fmt"
  4. "gin-vue-admin/global/response"
  5. "gin-vue-admin/model"
  6. "gin-vue-admin/model/request"
  7. "gin-vue-admin/service"
  8. "github.com/gin-gonic/gin"
  9. )
  10. // @Tags authority
  11. // @Summary 创建角色
  12. // @Security ApiKeyAuth
  13. // @accept application/json
  14. // @Produce application/json
  15. // @Param data body model.SysAuthority true "创建角色"
  16. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  17. // @Router /authority/createAuthority [post]
  18. func CreateAuthority(c *gin.Context) {
  19. var auth model.SysAuthority
  20. _ = c.ShouldBindJSON(&auth)
  21. err, authBack := service.CreateAuthority(&auth)
  22. if err != nil {
  23. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("创建失败,%v", err), c)
  24. } else {
  25. response.Result(response.SUCCESS, gin.H{
  26. "authority": authBack,
  27. }, fmt.Sprintf("创建成功,%v", err), c)
  28. }
  29. }
  30. // @Tags authority
  31. // @Summary 删除角色
  32. // @Security ApiKeyAuth
  33. // @accept application/json
  34. // @Produce application/json
  35. // @Param data body model.SysAuthority true "删除角色"
  36. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  37. // @Router /authority/deleteAuthority [post]
  38. func DeleteAuthority(c *gin.Context) {
  39. var a model.SysAuthority
  40. _ = c.ShouldBindJSON(&a)
  41. //删除角色之前需要判断是否有用户正在使用此角色
  42. err := service.DeleteAuthority(a)
  43. if err != nil {
  44. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("删除失败,%v", err), c)
  45. } else {
  46. response.Result(response.SUCCESS, gin.H{}, "删除失败", c)
  47. }
  48. }
  49. // @Tags authority
  50. // @Summary 分页获取角色列表
  51. // @Security ApiKeyAuth
  52. // @accept application/json
  53. // @Produce application/json
  54. // @Param data body model.PageInfo true "分页获取用户列表"
  55. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  56. // @Router /authority/getAuthorityList [post]
  57. func GetAuthorityList(c *gin.Context) {
  58. var pageInfo request.PageInfo
  59. _ = c.ShouldBindJSON(&pageInfo)
  60. err, list, total := service.GetAuthorityInfoList(pageInfo)
  61. if err != nil {
  62. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
  63. } else {
  64. response.Result(response.SUCCESS, gin.H{
  65. "list": list,
  66. "total": total,
  67. "page": pageInfo.Page,
  68. "pageSize": pageInfo.PageSize,
  69. }, "获取数据成功", c)
  70. }
  71. }
  72. // @Tags authority
  73. // @Summary 设置角色资源权限
  74. // @Security ApiKeyAuth
  75. // @accept application/json
  76. // @Produce application/json
  77. // @Param data body model.SysAuthority true "设置角色资源权限"
  78. // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
  79. // @Router /authority/setDataAuthority [post]
  80. func SetDataAuthority(c *gin.Context) {
  81. var auth model.SysAuthority
  82. _ = c.ShouldBindJSON(&auth)
  83. err := service.SetDataAuthority(auth)
  84. if err != nil {
  85. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("设置关联失败,%v", err), c)
  86. } else {
  87. response.Result(response.SUCCESS, gin.H{}, "获取数据成功", c)
  88. }
  89. }