sys_api.go 3.8 KB

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