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.

92 lines
2.9 KiB

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