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.

172 lines
5.6 KiB

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