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.

93 lines
2.8 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.PageInfo true "分页获取用户列表"
  54. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  55. // @Router /authority/getAuthorityList [post]
  56. func GetAuthorityList(c *gin.Context) {
  57. var pageInfo request.PageInfo
  58. _ = c.ShouldBindJSON(&pageInfo)
  59. err, list, total := service.GetAuthorityInfoList(pageInfo)
  60. if err != nil {
  61. response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
  62. } else {
  63. response.OkWithData(resp.PageResult{
  64. List: list,
  65. Total: total,
  66. Page: pageInfo.Page,
  67. PageSize: pageInfo.PageSize,
  68. }, c)
  69. }
  70. }
  71. // @Tags authority
  72. // @Summary 设置角色资源权限
  73. // @Security ApiKeyAuth
  74. // @accept application/json
  75. // @Produce application/json
  76. // @Param data body model.SysAuthority true "设置角色资源权限"
  77. // @Success 200 {string} string "{"success":true,"data":{},"msg":"设置成功"}"
  78. // @Router /authority/setDataAuthority [post]
  79. func SetDataAuthority(c *gin.Context) {
  80. var auth model.SysAuthority
  81. _ = c.ShouldBindJSON(&auth)
  82. err := service.SetDataAuthority(auth)
  83. if err != nil {
  84. response.FailWithMessage(fmt.Sprintf("设置关联失败,%v", err), c)
  85. } else {
  86. response.Ok(c)
  87. }
  88. }