You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
4.1 KiB

  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. resp "gin-vue-admin/model/response"
  8. "gin-vue-admin/service"
  9. "github.com/gin-gonic/gin"
  10. )
  11. // @Tags authority
  12. // @Summary 创建角色
  13. // @Security ApiKeyAuth
  14. // @accept application/json
  15. // @Produce application/json
  16. // @Param data body model.SysAuthority true "创建角色"
  17. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  18. // @Router /authority/createAuthority [post]
  19. func CreateAuthority(c *gin.Context) {
  20. var auth model.SysAuthority
  21. _ = c.ShouldBindJSON(&auth)
  22. err, authBack := service.CreateAuthority(auth)
  23. if err != nil {
  24. response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c)
  25. } else {
  26. response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c)
  27. }
  28. }
  29. // @Tags authority
  30. // @Summary 拷贝角色
  31. // @Security ApiKeyAuth
  32. // @accept application/json
  33. // @Produce application/json
  34. // @Param data body response.SysAuthorityCopyResponse true "拷贝角色"
  35. // @Success 200 {string} string "{"success":true,"data":{},"msg":"拷贝成功"}"
  36. // @Router /authority/copyAuthority [post]
  37. func CopyAuthority(c *gin.Context) {
  38. var copyInfo resp.SysAuthorityCopyResponse
  39. _ = c.ShouldBindJSON(&copyInfo)
  40. err, authBack := service.CopyAuthority(copyInfo)
  41. if err != nil {
  42. response.FailWithMessage(fmt.Sprintf("拷贝失败,%v", err), c)
  43. } else {
  44. response.OkWithData(resp.SysAuthorityResponse{Authority: authBack}, c)
  45. }
  46. }
  47. // @Tags authority
  48. // @Summary 删除角色
  49. // @Security ApiKeyAuth
  50. // @accept application/json
  51. // @Produce application/json
  52. // @Param data body model.SysAuthority true "删除角色"
  53. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  54. // @Router /authority/deleteAuthority [post]
  55. func DeleteAuthority(c *gin.Context) {
  56. var a model.SysAuthority
  57. _ = c.ShouldBindJSON(&a)
  58. //删除角色之前需要判断是否有用户正在使用此角色
  59. err := service.DeleteAuthority(&a)
  60. if err != nil {
  61. response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
  62. } else {
  63. response.OkWithMessage("删除成功", c)
  64. }
  65. }
  66. // @Tags authority
  67. // @Summary 设置角色资源权限
  68. // @Security ApiKeyAuth
  69. // @accept application/json
  70. // @Produce application/json
  71. // @Param data body model.SysAuthority true "设置角色资源权限"
  72. // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
  73. // @Router /authority/updateAuthority [post]
  74. func UpdateAuthority(c *gin.Context) {
  75. var auth model.SysAuthority
  76. _ = c.ShouldBindJSON(&auth)
  77. err, authority := service.UpdateAuthority(auth)
  78. if err != nil {
  79. response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
  80. } else {
  81. response.OkWithData(resp.SysAuthorityResponse{authority}, c)
  82. }
  83. }
  84. // @Tags authority
  85. // @Summary 分页获取角色列表
  86. // @Security ApiKeyAuth
  87. // @accept application/json
  88. // @Produce application/json
  89. // @Param data body request.PageInfo true "分页获取用户列表"
  90. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  91. // @Router /authority/getAuthorityList [post]
  92. func GetAuthorityList(c *gin.Context) {
  93. var pageInfo request.PageInfo
  94. _ = c.ShouldBindJSON(&pageInfo)
  95. err, list, total := service.GetAuthorityInfoList(pageInfo)
  96. if err != nil {
  97. response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
  98. } else {
  99. response.OkWithData(resp.PageResult{
  100. List: list,
  101. Total: total,
  102. Page: pageInfo.Page,
  103. PageSize: pageInfo.PageSize,
  104. }, c)
  105. }
  106. }
  107. // @Tags authority
  108. // @Summary 设置角色资源权限
  109. // @Security ApiKeyAuth
  110. // @accept application/json
  111. // @Produce application/json
  112. // @Param data body model.SysAuthority true "设置角色资源权限"
  113. // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
  114. // @Router /authority/setDataAuthority [post]
  115. func SetDataAuthority(c *gin.Context) {
  116. var auth model.SysAuthority
  117. _ = c.ShouldBindJSON(&auth)
  118. err := service.SetDataAuthority(auth)
  119. if err != nil {
  120. response.FailWithMessage(fmt.Sprintf("设置关联失败,%v", err), c)
  121. } else {
  122. response.Ok(c)
  123. }
  124. }