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.

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