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.

152 lines
4.2 KiB

5 years ago
5 years ago
  1. package api
  2. import (
  3. "fmt"
  4. "gin-vue-admin/controller/servers"
  5. "gin-vue-admin/model/modelInterface"
  6. "gin-vue-admin/model/sysModel"
  7. "github.com/gin-gonic/gin"
  8. )
  9. type CreateApiParams struct {
  10. Path string `json:"path"`
  11. Description string `json:"description"`
  12. }
  13. type DeleteApiParams struct {
  14. ID uint `json:"id"`
  15. }
  16. // @Tags SysApi
  17. // @Summary 创建基础api
  18. // @Security ApiKeyAuth
  19. // @accept application/json
  20. // @Produce application/json
  21. // @Param data body api.CreateApiParams true "创建api"
  22. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  23. // @Router /api/createApi [post]
  24. func CreateApi(c *gin.Context) {
  25. var api sysModel.SysApi
  26. _ = c.ShouldBindJSON(&api)
  27. err := api.CreateApi()
  28. if err != nil {
  29. servers.ReportFormat(c, false, fmt.Sprintf("创建失败:%v", err), gin.H{})
  30. } else {
  31. servers.ReportFormat(c, true, "创建成功", gin.H{})
  32. }
  33. }
  34. // @Tags SysApi
  35. // @Summary 删除指定api
  36. // @Security ApiKeyAuth
  37. // @accept application/json
  38. // @Produce application/json
  39. // @Param data body sysModel.SysApi true "删除api"
  40. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  41. // @Router /api/deleteApi [post]
  42. func DeleteApi(c *gin.Context) {
  43. var a sysModel.SysApi
  44. _ = c.ShouldBindJSON(&a)
  45. err := a.DeleteApi()
  46. if err != nil {
  47. servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{})
  48. } else {
  49. servers.ReportFormat(c, true, "删除成功", gin.H{})
  50. }
  51. }
  52. type AuthAndPathIn struct {
  53. AuthorityId string `json:"authorityId"`
  54. ApiIds []uint `json:"apiIds"`
  55. }
  56. //条件搜索后端看此api
  57. // @Tags SysApi
  58. // @Summary 分页获取API列表
  59. // @Security ApiKeyAuth
  60. // @accept application/json
  61. // @Produce application/json
  62. // @Param data body modelInterface.PageInfo true "分页获取API列表"
  63. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  64. // @Router /api/getApiList [post]
  65. func GetApiList(c *gin.Context) {
  66. // 此结构体仅本方法使用
  67. type searchParams struct {
  68. sysModel.SysApi
  69. modelInterface.PageInfo
  70. }
  71. var sp searchParams
  72. _ = c.ShouldBindJSON(&sp)
  73. err, list, total := sp.SysApi.GetInfoList(sp.PageInfo)
  74. if err != nil {
  75. servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
  76. } else {
  77. servers.ReportFormat(c, true, "获取数据成功", gin.H{
  78. "list": list,
  79. "total": total,
  80. "page": sp.PageInfo.Page,
  81. "pageSize": sp.PageInfo.PageSize,
  82. })
  83. }
  84. }
  85. // @Tags SysApi
  86. // @Summary 根据id获取api
  87. // @Security ApiKeyAuth
  88. // @accept application/json
  89. // @Produce application/json
  90. // @Param data body modelInterface.PageInfo true "分页获取用户列表"
  91. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  92. // @Router /api/getApiById [post]
  93. func GetApiById(c *gin.Context) {
  94. var idInfo GetById
  95. _ = c.ShouldBindJSON(&idInfo)
  96. err, api := new(sysModel.SysApi).GetApiById(idInfo.Id)
  97. if err != nil {
  98. servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
  99. } else {
  100. servers.ReportFormat(c, true, "获取数据成功", gin.H{
  101. "api": api,
  102. })
  103. }
  104. }
  105. // @Tags SysApi
  106. // @Summary 创建基础api
  107. // @Security ApiKeyAuth
  108. // @accept application/json
  109. // @Produce application/json
  110. // @Param data body api.CreateApiParams true "创建api"
  111. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  112. // @Router /api/updataApi [post]
  113. func UpdataApi(c *gin.Context) {
  114. var api sysModel.SysApi
  115. _ = c.ShouldBindJSON(&api)
  116. err := api.UpdataApi()
  117. if err != nil {
  118. servers.ReportFormat(c, false, fmt.Sprintf("修改数据失败,%v", err), gin.H{})
  119. } else {
  120. servers.ReportFormat(c, true, "修改数据成功", gin.H{})
  121. }
  122. }
  123. // @Tags SysApi
  124. // @Summary 获取所有的Api 不分页
  125. // @Security ApiKeyAuth
  126. // @accept application/json
  127. // @Produce application/json
  128. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  129. // @Router /api/getAllApis [post]
  130. func GetAllApis(c *gin.Context) {
  131. err, apis := new(sysModel.SysApi).GetAllApis()
  132. if err != nil {
  133. servers.ReportFormat(c, false, fmt.Sprintf("获取数据失败,%v", err), gin.H{})
  134. } else {
  135. servers.ReportFormat(c, true, "获取数据成功", gin.H{
  136. "apis": apis,
  137. })
  138. }
  139. }