jt_news.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. "git.getensh.com/common/gopkgs/logger"
  6. "git.getensh.com/common/gopkgs/tasker/httptasker"
  7. "git.getensh.com/common/gopkgs/util"
  8. "github.com/gin-gonic/gin"
  9. "go.uber.org/zap"
  10. "net/http"
  11. "xingjia-official-gateway/apis"
  12. "xingjia-official-gateway/consts"
  13. "xingjia-official-gateway/errors"
  14. "xingjia-official-gateway/impl/v1/jt"
  15. param_v1 "xingjia-official-gateway/param/v1"
  16. )
  17. //
  18. // @Summary 兴嘉要闻列表
  19. // @Description 兴嘉要闻列表
  20. // @Tags 兴嘉要闻
  21. // @Accept json
  22. // @Produce json
  23. // @Param page query int false " "
  24. // @Param page_size query int false " "
  25. // @Success 200 {object} v1.JtContentListResponse
  26. // @Failure 500 {object} base.HTTPError
  27. // @Router /api/v1/jt/news [get]
  28. func (c *Controller) JtNewsList(ctx *gin.Context) {
  29. // 解析参数
  30. req := &param_v1.JtContentListRequest{}
  31. parseParamTask := func() error {
  32. err := util.ShouldBind(ctx, nil, nil, &req.JtContentListQuery, nil)
  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. // 响应数据
  44. resp := param_v1.JtContentListResponse{}
  45. rpcReq := &apis.JtContentListRequest{
  46. ContentType: consts.OperationModuleNews,
  47. PageSize: req.PageSize,
  48. Page: req.Page,
  49. }
  50. rpcRsp, err := jt.JtContentList(ctx, rpcReq)
  51. if err != nil {
  52. s, _ := json.MarshalToString(req)
  53. logger.Error("func",
  54. zap.String("call", "jt.JtContentList"),
  55. zap.String("params", s),
  56. zap.String("error", err.Error()))
  57. return errors.ErrorTransForm(err)
  58. }
  59. if rpcRsp.List == nil {
  60. rpcRsp.List = make([]*apis.JtContentItem, 0)
  61. }
  62. resp.Data = *rpcRsp
  63. ctx.JSON(http.StatusOK, resp)
  64. return nil
  65. }
  66. // 执行任务
  67. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  68. }