sys_api.go 3.9 KB

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