ot_ifram.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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 OtIfram struct {
  14. api.Api
  15. }
  16. // GetPage 获取OtIfram列表
  17. // @Summary 获取OtIfram列表
  18. // @Description 获取OtIfram列表
  19. // @Tags OtIfram
  20. // @Param url query string false "iframe地址"
  21. // @Param pageTag query string false "页面标识"
  22. // @Param appId query int64 false "AppID"
  23. // @Param pageSize query int false "页条数"
  24. // @Param pageIndex query int false "页码"
  25. // @Success 200 {object} response.Response{data=response.Page{list=[]models.OtIfram}} "{"code": 200, "data": [...]}"
  26. // @Router /api/v1/ot-ifram [get]
  27. // @Security Bearer
  28. func (e OtIfram) GetPage(c *gin.Context) {
  29. req := dto.OtIframGetPageReq{}
  30. s := service.OtIfram{}
  31. err := e.MakeContext(c).
  32. MakeOrm().
  33. Bind(&req).
  34. MakeService(&s.Service).
  35. Errors
  36. if err != nil {
  37. e.Logger.Error(err)
  38. e.Error(500, err, err.Error())
  39. return
  40. }
  41. p := actions.GetPermissionFromContext(c)
  42. list := make([]models.OtIfram, 0)
  43. var count int64
  44. err = s.GetPage(&req, p, &list, &count)
  45. if err != nil {
  46. e.Error(500, err, fmt.Sprintf("获取OtIfram失败,\r\n失败信息 %s", err.Error()))
  47. return
  48. }
  49. e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
  50. }
  51. // Get 获取OtIfram
  52. // @Summary 获取OtIfram
  53. // @Description 获取OtIfram
  54. // @Tags OtIfram
  55. // @Param id path int false "id"
  56. // @Success 200 {object} response.Response{data=models.OtIfram} "{"code": 200, "data": [...]}"
  57. // @Router /api/v1/ot-ifram/{id} [get]
  58. // @Security Bearer
  59. func (e OtIfram) Get(c *gin.Context) {
  60. req := dto.OtIframGetReq{}
  61. s := service.OtIfram{}
  62. err := e.MakeContext(c).
  63. MakeOrm().
  64. Bind(&req).
  65. MakeService(&s.Service).
  66. Errors
  67. if err != nil {
  68. e.Logger.Error(err)
  69. e.Error(500, err, err.Error())
  70. return
  71. }
  72. var object models.OtIfram
  73. p := actions.GetPermissionFromContext(c)
  74. err = s.Get(&req, p, &object)
  75. if err != nil {
  76. e.Error(500, err, fmt.Sprintf("获取OtIfram失败,\r\n失败信息 %s", err.Error()))
  77. return
  78. }
  79. e.OK(object, "查询成功")
  80. }
  81. // Insert 创建OtIfram
  82. // @Summary 创建OtIfram
  83. // @Description 创建OtIfram
  84. // @Tags OtIfram
  85. // @Accept application/json
  86. // @Product application/json
  87. // @Param data body dto.OtIframInsertReq true "data"
  88. // @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}"
  89. // @Router /api/v1/ot-ifram [post]
  90. // @Security Bearer
  91. func (e OtIfram) Insert(c *gin.Context) {
  92. req := dto.OtIframInsertReq{}
  93. s := service.OtIfram{}
  94. err := e.MakeContext(c).
  95. MakeOrm().
  96. Bind(&req).
  97. MakeService(&s.Service).
  98. Errors
  99. if err != nil {
  100. e.Logger.Error(err)
  101. e.Error(500, err, err.Error())
  102. return
  103. }
  104. // 设置创建人
  105. req.SetCreateBy(user.GetUserId(c))
  106. err = s.Insert(&req)
  107. if err != nil {
  108. e.Error(500, err, fmt.Sprintf("创建OtIfram失败,\r\n失败信息 %s", err.Error()))
  109. return
  110. }
  111. e.OK(req.GetId(), "创建成功")
  112. }
  113. // Update 修改OtIfram
  114. // @Summary 修改OtIfram
  115. // @Description 修改OtIfram
  116. // @Tags OtIfram
  117. // @Accept application/json
  118. // @Product application/json
  119. // @Param id path int true "id"
  120. // @Param data body dto.OtIframUpdateReq true "body"
  121. // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
  122. // @Router /api/v1/ot-ifram/{id} [put]
  123. // @Security Bearer
  124. func (e OtIfram) Update(c *gin.Context) {
  125. req := dto.OtIframUpdateReq{}
  126. s := service.OtIfram{}
  127. err := e.MakeContext(c).
  128. MakeOrm().
  129. Bind(&req).
  130. MakeService(&s.Service).
  131. Errors
  132. if err != nil {
  133. e.Logger.Error(err)
  134. e.Error(500, err, err.Error())
  135. return
  136. }
  137. req.SetUpdateBy(user.GetUserId(c))
  138. p := actions.GetPermissionFromContext(c)
  139. err = s.Update(&req, p)
  140. if err != nil {
  141. e.Error(500, err, fmt.Sprintf("修改OtIfram失败,\r\n失败信息 %s", err.Error()))
  142. return
  143. }
  144. e.OK(req.GetId(), "修改成功")
  145. }
  146. // Delete 删除OtIfram
  147. // @Summary 删除OtIfram
  148. // @Description 删除OtIfram
  149. // @Tags OtIfram
  150. // @Param data body dto.OtIframDeleteReq true "body"
  151. // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}"
  152. // @Router /api/v1/ot-ifram [delete]
  153. // @Security Bearer
  154. func (e OtIfram) Delete(c *gin.Context) {
  155. s := service.OtIfram{}
  156. req := dto.OtIframDeleteReq{}
  157. err := e.MakeContext(c).
  158. MakeOrm().
  159. Bind(&req).
  160. MakeService(&s.Service).
  161. Errors
  162. if err != nil {
  163. e.Logger.Error(err)
  164. e.Error(500, err, err.Error())
  165. return
  166. }
  167. // req.SetUpdateBy(user.GetUserId(c))
  168. p := actions.GetPermissionFromContext(c)
  169. err = s.Remove(&req, p)
  170. if err != nil {
  171. e.Error(500, err, fmt.Sprintf("删除OtIfram失败,\r\n失败信息 %s", err.Error()))
  172. return
  173. }
  174. e.OK(req.GetId(), "删除成功")
  175. }