ot_plugins.go 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. package apis
  2. import (
  3. "fmt"
  4. "github.com/gin-gonic/gin"
  5. "github.com/go-admin-team/go-admin-core/sdk/api"
  6. "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
  7. _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
  8. "go-admin/app/admin/models"
  9. "go-admin/app/admin/service"
  10. "go-admin/app/admin/service/dto"
  11. "go-admin/common/actions"
  12. )
  13. type OtPlugins struct {
  14. api.Api
  15. }
  16. // GetPage 获取OtPlugins列表
  17. // @Summary 获取OtPlugins列表
  18. // @Description 获取OtPlugins列表
  19. // @Tags OtPlugins
  20. // @Param name query string false "插件名"
  21. // @Param alias query string false "插件英文别名"
  22. // @Param pageSize query int false "页条数"
  23. // @Param pageIndex query int false "页码"
  24. // @Success 200 {object} response.Response{data=response.Page{list=[]models.OtPlugins}} "{"code": 200, "data": [...]}"
  25. // @Router /api/v1/ot-plugins [get]
  26. // @Security Bearer
  27. func (e OtPlugins) GetPage(c *gin.Context) {
  28. req := dto.OtPluginsGetPageReq{}
  29. s := service.OtPlugins{}
  30. err := e.MakeContext(c).
  31. MakeOrm().
  32. Bind(&req).
  33. MakeService(&s.Service).
  34. Errors
  35. if err != nil {
  36. e.Logger.Error(err)
  37. e.Error(500, err, err.Error())
  38. return
  39. }
  40. p := actions.GetPermissionFromContext(c)
  41. list := make([]models.OtPlugins, 0)
  42. var count int64
  43. err = s.GetPage(&req, p, &list, &count)
  44. if err != nil {
  45. e.Error(500, err, fmt.Sprintf("获取OtPlugins失败,\r\n失败信息 %s", err.Error()))
  46. return
  47. }
  48. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  49. }
  50. // Get 获取OtPlugins
  51. // @Summary 获取OtPlugins
  52. // @Description 获取OtPlugins
  53. // @Tags OtPlugins
  54. // @Param id path int false "id"
  55. // @Success 200 {object} response.Response{data=models.OtPlugins} "{"code": 200, "data": [...]}"
  56. // @Router /api/v1/ot-plugins/{id} [get]
  57. // @Security Bearer
  58. func (e OtPlugins) Get(c *gin.Context) {
  59. req := dto.OtPluginsGetReq{}
  60. s := service.OtPlugins{}
  61. err := e.MakeContext(c).
  62. MakeOrm().
  63. Bind(&req).
  64. MakeService(&s.Service).
  65. Errors
  66. if err != nil {
  67. e.Logger.Error(err)
  68. e.Error(500, err, err.Error())
  69. return
  70. }
  71. var object models.OtPlugins
  72. p := actions.GetPermissionFromContext(c)
  73. err = s.Get(&req, p, &object)
  74. if err != nil {
  75. e.Error(500, err, fmt.Sprintf("获取OtPlugins失败,\r\n失败信息 %s", err.Error()))
  76. return
  77. }
  78. e.OK(object, "查询成功")
  79. }
  80. // Insert 创建OtPlugins
  81. // @Summary 创建OtPlugins
  82. // @Description 创建OtPlugins
  83. // @Tags OtPlugins
  84. // @Accept application/json
  85. // @Product application/json
  86. // @Param data body dto.OtPluginsInsertReq true "data"
  87. // @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}"
  88. // @Router /api/v1/ot-plugins [post]
  89. // @Security Bearer
  90. func (e OtPlugins) Insert(c *gin.Context) {
  91. req := dto.OtPluginsInsertReq{}
  92. s := service.OtPlugins{}
  93. err := e.MakeContext(c).
  94. MakeOrm().
  95. Bind(&req).
  96. MakeService(&s.Service).
  97. Errors
  98. if err != nil {
  99. e.Logger.Error(err)
  100. e.Error(500, err, err.Error())
  101. return
  102. }
  103. // 设置创建人
  104. req.SetCreateBy(user.GetUserId(c))
  105. err = s.Insert(&req)
  106. if err != nil {
  107. e.Error(500, err, fmt.Sprintf("创建OtPlugins失败,\r\n失败信息 %s", err.Error()))
  108. return
  109. }
  110. e.OK(req.GetId(), "创建成功")
  111. }
  112. // Update 修改OtPlugins
  113. // @Summary 修改OtPlugins
  114. // @Description 修改OtPlugins
  115. // @Tags OtPlugins
  116. // @Accept application/json
  117. // @Product application/json
  118. // @Param id path int true "id"
  119. // @Param data body dto.OtPluginsUpdateReq true "body"
  120. // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
  121. // @Router /api/v1/ot-plugins/{id} [put]
  122. // @Security Bearer
  123. func (e OtPlugins) Update(c *gin.Context) {
  124. req := dto.OtPluginsUpdateReq{}
  125. s := service.OtPlugins{}
  126. err := e.MakeContext(c).
  127. MakeOrm().
  128. Bind(&req).
  129. MakeService(&s.Service).
  130. Errors
  131. if err != nil {
  132. e.Logger.Error(err)
  133. e.Error(500, err, err.Error())
  134. return
  135. }
  136. req.SetUpdateBy(user.GetUserId(c))
  137. p := actions.GetPermissionFromContext(c)
  138. err = s.Update(&req, p)
  139. if err != nil {
  140. e.Error(500, err, fmt.Sprintf("修改OtPlugins失败,\r\n失败信息 %s", err.Error()))
  141. return
  142. }
  143. e.OK(req.GetId(), "修改成功")
  144. }
  145. // Delete 删除OtPlugins
  146. // @Summary 删除OtPlugins
  147. // @Description 删除OtPlugins
  148. // @Tags OtPlugins
  149. // @Param data body dto.OtPluginsDeleteReq true "body"
  150. // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}"
  151. // @Router /api/v1/ot-plugins [delete]
  152. // @Security Bearer
  153. func (e OtPlugins) Delete(c *gin.Context) {
  154. s := service.OtPlugins{}
  155. req := dto.OtPluginsDeleteReq{}
  156. err := e.MakeContext(c).
  157. MakeOrm().
  158. Bind(&req).
  159. MakeService(&s.Service).
  160. Errors
  161. if err != nil {
  162. e.Logger.Error(err)
  163. e.Error(500, err, err.Error())
  164. return
  165. }
  166. // req.SetUpdateBy(user.GetUserId(c))
  167. p := actions.GetPermissionFromContext(c)
  168. err = s.Remove(&req, p)
  169. if err != nil {
  170. e.Error(500, err, fmt.Sprintf("删除OtPlugins失败,\r\n失败信息 %s", err.Error()))
  171. return
  172. }
  173. e.OK(req.GetId(), "删除成功")
  174. }
  175. func (e OtPlugins) GetPluginsWithRole(c *gin.Context) {
  176. req := dto.OtPluginsGetPageReq{}
  177. s := service.OtPlugins{}
  178. err := e.MakeContext(c).
  179. MakeOrm().
  180. Bind(&req).
  181. MakeService(&s.Service).
  182. Errors
  183. if err != nil {
  184. e.Logger.Error(err)
  185. e.Error(500, err, err.Error())
  186. return
  187. }
  188. p := actions.GetPermissionFromContext(c)
  189. list := make([]models.OtPlugins, 0)
  190. var count int64
  191. err = s.GetPage(&req, p, &list, &count)
  192. if err != nil {
  193. e.Error(500, err, fmt.Sprintf("获取OtPlugins失败,\r\n失败信息 %s", err.Error()))
  194. return
  195. }
  196. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  197. }