page_pic.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. // Copyright 2019 github.com. All rights reserved.
  2. // Use of this source code is governed by github.com.
  3. package v1
  4. import (
  5. "net/http"
  6. "xingjia-management-gateway/apis"
  7. "xingjia-management-gateway/errors"
  8. "xingjia-management-gateway/impl/v1/page_pic"
  9. param_v1 "xingjia-management-gateway/param/v1"
  10. "xingjia-management-gateway/utils"
  11. "git.getensh.com/common/gopkgs/logger"
  12. "git.getensh.com/common/gopkgs/tasker/httptasker"
  13. "git.getensh.com/common/gopkgs/util"
  14. "github.com/gin-gonic/gin"
  15. "go.uber.org/zap"
  16. )
  17. //
  18. // @Summary 添加首页顶层图片
  19. // @Description 添加首页顶层图片
  20. // @Tags 首页顶层图片
  21. // @Accept json
  22. // @Produce json
  23. // @Param token header string true " "
  24. // @Param body body v1.PagePicAddBody true " "
  25. // @Success 200 {object} v1.PagePicAddResponse
  26. // @Failure 500 {object} base.HTTPError
  27. // @Router /api/v1/jt/page_pic [post]
  28. func (c *Controller) PagePicAdd(ctx *gin.Context) {
  29. // 解析参数
  30. req := &param_v1.PagePicAddRequest{}
  31. parseParamTask := func() error {
  32. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.PagePicAddBody)
  33. if err != nil {
  34. logger.Error("func",
  35. zap.String("call", "util.ShouldBind"),
  36. zap.String("error", err.Error()))
  37. return errors.ParamsError
  38. }
  39. return nil
  40. }
  41. // 业务处理
  42. handleServiceTask := func() error {
  43. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  44. if err != nil {
  45. return err
  46. }
  47. // 响应数据
  48. resp := param_v1.PagePicAddResponse{}
  49. rpcReq := &apis.PagePicAddRequest{
  50. SelfId: tokenInfo.Uid,
  51. SelfName: tokenInfo.User,
  52. Pic: req.Pic,
  53. }
  54. _, err = page_pic.PagePicAdd(ctx, rpcReq)
  55. if err != nil {
  56. s, _ := json.MarshalToString(req)
  57. logger.Error("func",
  58. zap.String("call", "page_pic.PagePicAdd"),
  59. zap.String("params", s),
  60. zap.String("error", err.Error()))
  61. return errors.ErrorTransForm(err)
  62. }
  63. ctx.JSON(http.StatusOK, resp)
  64. return nil
  65. }
  66. // 执行任务
  67. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  68. }
  69. //
  70. // @Summary 修改首页顶层图片
  71. // @Description 修改首页顶层图片
  72. // @Tags 首页顶层图片
  73. // @Accept json
  74. // @Produce json
  75. // @Param token header string true " "
  76. // @Param body body v1.PagePicUpdateBody true " "
  77. // @Success 200 {object} v1.PagePicUpdateResponse
  78. // @Failure 500 {object} base.HTTPError
  79. // @Router /api/v1/jt/page_pic [put]
  80. func (c *Controller) PagePicUpdate(ctx *gin.Context) {
  81. // 解析参数
  82. req := &param_v1.PagePicUpdateRequest{}
  83. parseParamTask := func() error {
  84. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.PagePicUpdateBody)
  85. if err != nil {
  86. logger.Error("func",
  87. zap.String("call", "util.ShouldBind"),
  88. zap.String("error", err.Error()))
  89. return errors.ParamsError
  90. }
  91. return nil
  92. }
  93. // 业务处理
  94. handleServiceTask := func() error {
  95. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  96. if err != nil {
  97. return err
  98. }
  99. // 响应数据
  100. resp := param_v1.PagePicUpdateResponse{}
  101. rpcReq := &apis.PagePicUpdateRequest{
  102. Pic: req.Pic,
  103. SelfId: tokenInfo.Uid,
  104. SelfName: tokenInfo.User,
  105. Id: req.Id,
  106. }
  107. _, err = page_pic.PagePicUpdate(ctx, rpcReq)
  108. if err != nil {
  109. s, _ := json.MarshalToString(req)
  110. logger.Error("func",
  111. zap.String("call", "page_pic.PagePicUpdate"),
  112. zap.String("params", s),
  113. zap.String("error", err.Error()))
  114. return errors.ErrorTransForm(err)
  115. }
  116. ctx.JSON(http.StatusOK, resp)
  117. return nil
  118. }
  119. // 执行任务
  120. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  121. }
  122. //
  123. // @Summary 删除首页顶层图片
  124. // @Description 删除首页顶层图片
  125. // @Tags 首页顶层图片
  126. // @Accept json
  127. // @Produce json
  128. // @Param token header string true " "
  129. // @Param id query int true " 记录id"
  130. // @Success 200 {object} v1.PagePicDelResponse
  131. // @Failure 500 {object} base.HTTPError
  132. // @Router /api/v1/jt/page_pic [delete]
  133. func (c *Controller) PagePicDel(ctx *gin.Context) {
  134. // 解析参数
  135. req := &param_v1.PagePicDelRequest{}
  136. parseParamTask := func() error {
  137. err := util.ShouldBind(ctx, &req.Header, nil, &req.PagePicDelQuery, nil)
  138. if err != nil {
  139. logger.Error("func",
  140. zap.String("call", "util.ShouldBind"),
  141. zap.String("error", err.Error()))
  142. return errors.ParamsError
  143. }
  144. return nil
  145. }
  146. // 业务处理
  147. handleServiceTask := func() error {
  148. tokenInfo, err := utils.GetJwtTokenFromCtx(ctx)
  149. if err != nil {
  150. return err
  151. }
  152. // 响应数据
  153. resp := param_v1.PagePicDelResponse{}
  154. rpcReq := &apis.PagePicDelRequest{
  155. SelfId: tokenInfo.Uid,
  156. SelfName: tokenInfo.User,
  157. Id: req.Id,
  158. }
  159. _, err = page_pic.PagePicDel(ctx, rpcReq)
  160. if err != nil {
  161. s, _ := json.MarshalToString(req)
  162. logger.Error("func",
  163. zap.String("call", "page_pic.PagePicDel"),
  164. zap.String("params", s),
  165. zap.String("error", err.Error()))
  166. return errors.ErrorTransForm(err)
  167. }
  168. ctx.JSON(http.StatusOK, resp)
  169. return nil
  170. }
  171. // 执行任务
  172. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  173. }
  174. //
  175. // @Summary 首页顶层图片列表
  176. // @Description 首页顶层图片列表
  177. // @Tags 首页顶层图片
  178. // @Accept json
  179. // @Produce json
  180. // @Param token header string true " "
  181. // @Param page query int false " "
  182. // @Param page_size query int false " "
  183. // @Success 200 {object} v1.PagePicListResponse
  184. // @Failure 500 {object} base.HTTPError
  185. // @Router /api/v1/jt/page_pic [get]
  186. func (c *Controller) PagePicList(ctx *gin.Context) {
  187. // 解析参数
  188. req := &param_v1.PagePicListRequest{}
  189. parseParamTask := func() error {
  190. err := util.ShouldBind(ctx, &req.Header, nil, &req.PagePicListQuery, nil)
  191. if err != nil {
  192. logger.Error("func",
  193. zap.String("call", "util.ShouldBind"),
  194. zap.String("error", err.Error()))
  195. return errors.ParamsError
  196. }
  197. return nil
  198. }
  199. // 业务处理
  200. handleServiceTask := func() error {
  201. // 响应数据
  202. resp := param_v1.PagePicListResponse{}
  203. rpcReq := &apis.PagePicListRequest{
  204. PageSize: req.PageSize,
  205. Page: req.Page,
  206. }
  207. rpcRsp, err := page_pic.PagePicList(ctx, rpcReq)
  208. if err != nil {
  209. s, _ := json.MarshalToString(req)
  210. logger.Error("func",
  211. zap.String("call", "page_pic.PagePicList"),
  212. zap.String("params", s),
  213. zap.String("error", err.Error()))
  214. return errors.ErrorTransForm(err)
  215. }
  216. if rpcRsp.List == nil {
  217. rpcRsp.List = make([]*apis.PagePicItem, 0)
  218. }
  219. resp.Data = *rpcRsp
  220. ctx.JSON(http.StatusOK, resp)
  221. return nil
  222. }
  223. // 执行任务
  224. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  225. }