sys_api.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. package system
  2. import (
  3. "github.com/flipped-aurora/gin-vue-admin/server/global"
  4. "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
  5. "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
  6. "github.com/flipped-aurora/gin-vue-admin/server/model/system"
  7. systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
  8. systemRes "github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
  9. "github.com/flipped-aurora/gin-vue-admin/server/utils"
  10. "github.com/gin-gonic/gin"
  11. "go.uber.org/zap"
  12. )
  13. type SystemApiApi struct {
  14. }
  15. // @Tags SysApi
  16. // @Summary 创建基础api
  17. // @Security ApiKeyAuth
  18. // @accept application/json
  19. // @Produce application/json
  20. // @Param data body system.SysApi true "api路径, api中文描述, api组, 方法"
  21. // @Success 200 {string} string "{"success":true,"data":{},"msg":"创建成功"}"
  22. // @Router /api/createApi [post]
  23. func (s *SystemApiApi) CreateApi(c *gin.Context) {
  24. var api system.SysApi
  25. _ = c.ShouldBindJSON(&api)
  26. if err := utils.Verify(api, utils.ApiVerify); err != nil {
  27. response.FailWithMessage(err.Error(), c)
  28. return
  29. }
  30. if err := apiService.CreateApi(api); err != nil {
  31. global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
  32. response.FailWithMessage("创建失败", c)
  33. } else {
  34. response.OkWithMessage("创建成功", c)
  35. }
  36. }
  37. // @Tags SysApi
  38. // @Summary 删除api
  39. // @Security ApiKeyAuth
  40. // @accept application/json
  41. // @Produce application/json
  42. // @Param data body system.SysApi true "ID"
  43. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  44. // @Router /api/deleteApi [post]
  45. func (s *SystemApiApi) DeleteApi(c *gin.Context) {
  46. var api system.SysApi
  47. _ = c.ShouldBindJSON(&api)
  48. if err := utils.Verify(api.GVA_MODEL, utils.IdVerify); err != nil {
  49. response.FailWithMessage(err.Error(), c)
  50. return
  51. }
  52. if err := apiService.DeleteApi(api); err != nil {
  53. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  54. response.FailWithMessage("删除失败", c)
  55. } else {
  56. response.OkWithMessage("删除成功", c)
  57. }
  58. }
  59. // @Tags SysApi
  60. // @Summary 分页获取API列表
  61. // @Security ApiKeyAuth
  62. // @accept application/json
  63. // @Produce application/json
  64. // @Param data body systemReq.SearchApiParams true "分页获取API列表"
  65. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  66. // @Router /api/getApiList [post]
  67. func (s *SystemApiApi) GetApiList(c *gin.Context) {
  68. var pageInfo systemReq.SearchApiParams
  69. _ = c.ShouldBindJSON(&pageInfo)
  70. if err := utils.Verify(pageInfo.PageInfo, utils.PageInfoVerify); err != nil {
  71. response.FailWithMessage(err.Error(), c)
  72. return
  73. }
  74. if err, list, total := apiService.GetAPIInfoList(pageInfo.SysApi, pageInfo.PageInfo, pageInfo.OrderKey, pageInfo.Desc); err != nil {
  75. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  76. response.FailWithMessage("获取失败", c)
  77. } else {
  78. response.OkWithDetailed(response.PageResult{
  79. List: list,
  80. Total: total,
  81. Page: pageInfo.Page,
  82. PageSize: pageInfo.PageSize,
  83. }, "获取成功", c)
  84. }
  85. }
  86. // @Tags SysApi
  87. // @Summary 根据id获取api
  88. // @Security ApiKeyAuth
  89. // @accept application/json
  90. // @Produce application/json
  91. // @Param data body request.GetById true "根据id获取api"
  92. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  93. // @Router /api/getApiById [post]
  94. func (s *SystemApiApi) GetApiById(c *gin.Context) {
  95. var idInfo request.GetById
  96. _ = c.ShouldBindJSON(&idInfo)
  97. if err := utils.Verify(idInfo, utils.IdVerify); err != nil {
  98. response.FailWithMessage(err.Error(), c)
  99. return
  100. }
  101. err, api := apiService.GetApiById(idInfo.ID)
  102. if err != nil {
  103. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  104. response.FailWithMessage("获取失败", c)
  105. } else {
  106. response.OkWithData(systemRes.SysAPIResponse{Api: api}, c)
  107. }
  108. }
  109. // @Tags SysApi
  110. // @Summary 创建基础api
  111. // @Security ApiKeyAuth
  112. // @accept application/json
  113. // @Produce application/json
  114. // @Param data body system.SysApi true "api路径, api中文描述, api组, 方法"
  115. // @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
  116. // @Router /api/updateApi [post]
  117. func (s *SystemApiApi) UpdateApi(c *gin.Context) {
  118. var api system.SysApi
  119. _ = c.ShouldBindJSON(&api)
  120. if err := utils.Verify(api, utils.ApiVerify); err != nil {
  121. response.FailWithMessage(err.Error(), c)
  122. return
  123. }
  124. if err := apiService.UpdateApi(api); err != nil {
  125. global.GVA_LOG.Error("修改失败!", zap.Any("err", err))
  126. response.FailWithMessage("修改失败", c)
  127. } else {
  128. response.OkWithMessage("修改成功", c)
  129. }
  130. }
  131. // @Tags SysApi
  132. // @Summary 获取所有的Api 不分页
  133. // @Security ApiKeyAuth
  134. // @accept application/json
  135. // @Produce application/json
  136. // @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
  137. // @Router /api/getAllApis [post]
  138. func (s *SystemApiApi) GetAllApis(c *gin.Context) {
  139. if err, apis := apiService.GetAllApis(); err != nil {
  140. global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
  141. response.FailWithMessage("获取失败", c)
  142. } else {
  143. response.OkWithDetailed(systemRes.SysAPIListResponse{Apis: apis}, "获取成功", c)
  144. }
  145. }
  146. // @Tags SysApi
  147. // @Summary 删除选中Api
  148. // @Security ApiKeyAuth
  149. // @accept application/json
  150. // @Produce application/json
  151. // @Param data body request.IdsReq true "ID"
  152. // @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
  153. // @Router /api/deleteApisByIds [delete]
  154. func (s *SystemApiApi) DeleteApisByIds(c *gin.Context) {
  155. var ids request.IdsReq
  156. _ = c.ShouldBindJSON(&ids)
  157. if err := apiService.DeleteApisByIds(ids); err != nil {
  158. global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
  159. response.FailWithMessage("删除失败", c)
  160. } else {
  161. response.OkWithMessage("删除成功", c)
  162. }
  163. }