sys_api.go 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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. type CreateApiParams struct {
  9. Path string `json:"path"`
  10. Description string `json:"description"`
  11. }
  12. type DeleteApiParams struct {
  13. ID uint `json:"id"`
  14. }
  15. // @Tags SysApi
  16. // @Summary 创建基础api
  17. // @Security ApiKeyAuth
  18. // @accept application/json
  19. // @Produce application/json
  20. // @Param data body api.CreateApiParams true "创建api"
  21. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  22. // @Router /api/createApi [post]
  23. func CreateApi(c *gin.Context) {
  24. var api model.SysApi
  25. _ = c.ShouldBindJSON(&api)
  26. err := api.CreateApi()
  27. if err != nil {
  28. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("创建失败,%v", err), c)
  29. } else {
  30. response.Result(response.SUCCESS, gin.H{}, "创建成功", c)
  31. }
  32. }
  33. // @Tags SysApi
  34. // @Summary 删除指定api
  35. // @Security ApiKeyAuth
  36. // @accept application/json
  37. // @Produce application/json
  38. // @Param data body sysModel.SysApi true "删除api"
  39. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  40. // @Router /api/deleteApi [post]
  41. func DeleteApi(c *gin.Context) {
  42. var a model.SysApi
  43. _ = c.ShouldBindJSON(&a)
  44. err := a.DeleteApi()
  45. if err != nil {
  46. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("删除失败,%v", err), c)
  47. } else {
  48. response.Result(response.SUCCESS, gin.H{}, "删除成功", c)
  49. }
  50. }
  51. type AuthAndPathIn struct {
  52. AuthorityId string `json:"authorityId"`
  53. ApiIds []uint `json:"apiIds"`
  54. }
  55. //条件搜索后端看此api
  56. // @Tags SysApi
  57. // @Summary 分页获取API列表
  58. // @Security ApiKeyAuth
  59. // @accept application/json
  60. // @Produce application/json
  61. // @Param data body model.PageInfo true "分页获取API列表"
  62. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  63. // @Router /api/getApiList [post]
  64. func GetApiList(c *gin.Context) {
  65. // 此结构体仅本方法使用
  66. type searchParams struct {
  67. model.SysApi
  68. model.PageInfo
  69. }
  70. var sp searchParams
  71. _ = c.ShouldBindJSON(&sp)
  72. err, list, total := sp.SysApi.GetInfoList(sp.PageInfo)
  73. if err != nil {
  74. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
  75. } else {
  76. response.Result(response.SUCCESS, gin.H{
  77. "list": list,
  78. "total": total,
  79. "page": sp.PageInfo.Page,
  80. "pageSize": sp.PageInfo.PageSize,
  81. }, "删除成功", c)
  82. }
  83. }
  84. // @Tags SysApi
  85. // @Summary 根据id获取api
  86. // @Security ApiKeyAuth
  87. // @accept application/json
  88. // @Produce application/json
  89. // @Param data body model.PageInfo true "分页获取用户列表"
  90. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  91. // @Router /api/getApiById [post]
  92. func GetApiById(c *gin.Context) {
  93. var idInfo GetById
  94. _ = c.ShouldBindJSON(&idInfo)
  95. err, api := new(model.SysApi).GetApiById(idInfo.Id)
  96. if err != nil {
  97. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
  98. } else {
  99. response.Result(response.SUCCESS, gin.H{
  100. "api": api,
  101. }, "获取数据成功", c)
  102. }
  103. }
  104. // @Tags SysApi
  105. // @Summary 创建基础api
  106. // @Security ApiKeyAuth
  107. // @accept application/json
  108. // @Produce application/json
  109. // @Param data body api.CreateApiParams true "创建api"
  110. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  111. // @Router /api/updateApi [post]
  112. func UpdateApi(c *gin.Context) {
  113. var api model.SysApi
  114. _ = c.ShouldBindJSON(&api)
  115. err := api.UpdateApi()
  116. if err != nil {
  117. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("修改数据失败,%v", err), c)
  118. } else {
  119. response.Result(response.SUCCESS, gin.H{}, "修改数据成功", c)
  120. }
  121. }
  122. // @Tags SysApi
  123. // @Summary 获取所有的Api 不分页
  124. // @Security ApiKeyAuth
  125. // @accept application/json
  126. // @Produce application/json
  127. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  128. // @Router /api/getAllApis [post]
  129. func GetAllApis(c *gin.Context) {
  130. err, apis := new(model.SysApi).GetAllApis()
  131. if err != nil {
  132. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
  133. } else {
  134. response.Result(response.SUCCESS, gin.H{
  135. "apis": apis,
  136. }, "获取数据成功", c)
  137. }
  138. }