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.

130 lines
3.7 KiB

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