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.

112 lines
3.4 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 model.SysAuthority true "删除角色"
  35. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  36. // @Router /authority/deleteAuthority [post]
  37. func DeleteAuthority(c *gin.Context) {
  38. var a model.SysAuthority
  39. _ = c.ShouldBindJSON(&a)
  40. //删除角色之前需要判断是否有用户正在使用此角色
  41. err := service.DeleteAuthority(&a)
  42. if err != nil {
  43. response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
  44. } else {
  45. response.OkWithMessage("删除成功", c)
  46. }
  47. }
  48. // @Tags authority
  49. // @Summary 设置角色资源权限
  50. // @Security ApiKeyAuth
  51. // @accept application/json
  52. // @Produce application/json
  53. // @Param data body model.SysAuthority true "设置角色资源权限"
  54. // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
  55. // @Router /authority/updateAuthority [post]
  56. func UpdateAuthority(c *gin.Context) {
  57. var auth model.SysAuthority
  58. _ = c.ShouldBindJSON(&auth)
  59. err, authority := service.UpdateAuthority(auth)
  60. if err != nil {
  61. response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
  62. } else {
  63. response.OkWithData(resp.SysAuthorityResponse{authority}, c)
  64. }
  65. }
  66. // @Tags authority
  67. // @Summary 分页获取角色列表
  68. // @Security ApiKeyAuth
  69. // @accept application/json
  70. // @Produce application/json
  71. // @Param data body request.PageInfo true "分页获取用户列表"
  72. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  73. // @Router /authority/getAuthorityList [post]
  74. func GetAuthorityList(c *gin.Context) {
  75. var pageInfo request.PageInfo
  76. _ = c.ShouldBindJSON(&pageInfo)
  77. err, list, total := service.GetAuthorityInfoList(pageInfo)
  78. if err != nil {
  79. response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
  80. } else {
  81. response.OkWithData(resp.PageResult{
  82. List: list,
  83. Total: total,
  84. Page: pageInfo.Page,
  85. PageSize: pageInfo.PageSize,
  86. }, c)
  87. }
  88. }
  89. // @Tags authority
  90. // @Summary 设置角色资源权限
  91. // @Security ApiKeyAuth
  92. // @accept application/json
  93. // @Produce application/json
  94. // @Param data body model.SysAuthority true "设置角色资源权限"
  95. // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
  96. // @Router /authority/setDataAuthority [post]
  97. func SetDataAuthority(c *gin.Context) {
  98. var auth model.SysAuthority
  99. _ = c.ShouldBindJSON(&auth)
  100. err := service.SetDataAuthority(auth)
  101. if err != nil {
  102. response.FailWithMessage(fmt.Sprintf("设置关联失败,%v", err), c)
  103. } else {
  104. response.Ok(c)
  105. }
  106. }