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.

138 lines
4.0 KiB

5 years ago
5 years ago
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. "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 api.CreateApiParams 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 sysModel.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.PageInfo true "分页获取API列表"
  51. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  52. // @Router /api/getApiList [post]
  53. func GetApiList(c *gin.Context) {
  54. // 此结构体仅本方法使用
  55. type searchParams struct {
  56. model.SysApi
  57. model.PageInfo
  58. OrderKey string `json:"orderKey"`
  59. Desc bool `json:"desc"`
  60. }
  61. var sp searchParams
  62. _ = c.ShouldBindJSON(&sp)
  63. err, list, total := sp.SysApi.GetInfoList(sp.PageInfo, sp.OrderKey, sp.Desc)
  64. if err != nil {
  65. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
  66. } else {
  67. response.Result(response.SUCCESS, gin.H{
  68. "list": list,
  69. "total": total,
  70. "page": sp.PageInfo.Page,
  71. "pageSize": sp.PageInfo.PageSize,
  72. }, "删除成功", c)
  73. }
  74. }
  75. // @Tags SysApi
  76. // @Summary 根据id获取api
  77. // @Security ApiKeyAuth
  78. // @accept application/json
  79. // @Produce application/json
  80. // @Param data body model.PageInfo true "分页获取用户列表"
  81. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  82. // @Router /api/getApiById [post]
  83. func GetApiById(c *gin.Context) {
  84. var idInfo GetById
  85. _ = c.ShouldBindJSON(&idInfo)
  86. err, api := new(model.SysApi).GetApiById(idInfo.Id)
  87. if err != nil {
  88. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
  89. } else {
  90. response.Result(response.SUCCESS, gin.H{
  91. "api": api,
  92. }, "获取数据成功", c)
  93. }
  94. }
  95. // @Tags SysApi
  96. // @Summary 创建基础api
  97. // @Security ApiKeyAuth
  98. // @accept application/json
  99. // @Produce application/json
  100. // @Param data body api.CreateApiParams true "创建api"
  101. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  102. // @Router /api/updateApi [post]
  103. func UpdateApi(c *gin.Context) {
  104. var api model.SysApi
  105. _ = c.ShouldBindJSON(&api)
  106. err := api.UpdateApi()
  107. if err != nil {
  108. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("修改数据失败,%v", err), c)
  109. } else {
  110. response.Result(response.SUCCESS, gin.H{}, "修改数据成功", c)
  111. }
  112. }
  113. // @Tags SysApi
  114. // @Summary 获取所有的Api 不分页
  115. // @Security ApiKeyAuth
  116. // @accept application/json
  117. // @Produce application/json
  118. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  119. // @Router /api/getAllApis [post]
  120. func GetAllApis(c *gin.Context) {
  121. err, apis := new(model.SysApi).GetAllApis()
  122. if err != nil {
  123. response.Result(response.ERROR, gin.H{}, fmt.Sprintf("获取数据失败,%v", err), c)
  124. } else {
  125. response.Result(response.SUCCESS, gin.H{
  126. "apis": apis,
  127. }, "获取数据成功", c)
  128. }
  129. }