event.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. package v1
  2. import (
  3. "git.getensh.com/common/gopkgs/logger"
  4. "git.getensh.com/common/gopkgs/tasker/httptasker"
  5. "git.getensh.com/common/gopkgs/util"
  6. "github.com/gin-gonic/gin"
  7. "go.uber.org/zap"
  8. "net/http"
  9. "property-household-gateway/errors"
  10. param_v1 "property-household-gateway/param/v1"
  11. "property-household-gateway/pb"
  12. "property-household-gateway/pb/v1"
  13. "property-household-gateway/utils"
  14. )
  15. //
  16. // @Summary 社区活动报名
  17. // @Description 添加社区活动报名
  18. // @Tags 社区活动
  19. // @Accept json
  20. // @Produce json
  21. // @Param token header string true "token"
  22. // @Param body body v1.EventSignAddBody true "信息"
  23. // @Success 200 {object} v1.EventSignAddResponse
  24. // @Failure 500 {object} base.HTTPError
  25. // @Router /api/v1/service/event/sign [post]
  26. func (c *Controller) EventSignAdd(ctx *gin.Context) {
  27. // 解析参数
  28. req := &param_v1.EventSignAddRequest{}
  29. parseParamTask := func() error {
  30. err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.EventSignAddBody)
  31. if err != nil {
  32. logger.Error("func",
  33. zap.String("call", "util.ShouldBind"),
  34. zap.String("error", err.Error()))
  35. return errors.ParamsError
  36. }
  37. return nil
  38. }
  39. // 业务处理
  40. handleServiceTask := func() error {
  41. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  42. if err != nil {
  43. return err
  44. }
  45. // 响应数据
  46. resp := param_v1.EventSignAddResponse{}
  47. rpcReq := &v1.EventSignAddRequest{
  48. GardenId:req.GardenId,
  49. EventId:req.EventId,
  50. HouseholdUid:tokenInfo.Uid,
  51. Phone:req.Phone,
  52. Name:req.Name,
  53. Comment:req.Comment,
  54. Count:req.Count,
  55. }
  56. _, err = pb.Garden.EventSignAdd(ctx, rpcReq)
  57. if err != nil {
  58. s, _ := json.MarshalToString(req)
  59. logger.Error("func",
  60. zap.String("call", "pb.Garden.EventSignAdd"),
  61. zap.String("params", s),
  62. zap.String("error", err.Error()))
  63. return errors.ErrorTransForm(err)
  64. }
  65. ctx.JSON(http.StatusOK, resp)
  66. return nil
  67. }
  68. // 执行任务
  69. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  70. }
  71. //
  72. // @Summary 社区活动列表
  73. // @Description 社区活动列表
  74. // @Tags 社区活动
  75. // @Accept json
  76. // @Produce json
  77. // @Param token header string true "token"
  78. // @Param page query int false " "
  79. // @Param page_size query int false " "
  80. // @Param garden_id query int true " "
  81. // @Success 200 {object} v1.EventListResponse
  82. // @Failure 500 {object} base.HTTPError
  83. // @Router /api/v1/service/event [get]
  84. func (c *Controller) EventList(ctx *gin.Context) {
  85. // 解析参数
  86. req := &param_v1.EventListRequest{}
  87. parseParamTask := func() error {
  88. err := util.ShouldBind(ctx, &req.Header, nil, &req.EventListQuery, nil)
  89. if err != nil {
  90. logger.Error("func",
  91. zap.String("call", "util.ShouldBind"),
  92. zap.String("error", err.Error()))
  93. return errors.ParamsError
  94. }
  95. return nil
  96. }
  97. // 业务处理
  98. handleServiceTask := func() error {
  99. tokenInfo, err := utils.GetJwtTokenInfo(ctx)
  100. if err != nil {
  101. return err
  102. }
  103. // 响应数据
  104. resp := param_v1.EventListResponse{}
  105. rpcReq := &v1.EventListRequest{
  106. GardenId:req.GardenId,
  107. PageSize:req.PageSize,
  108. Page:req.Page,
  109. HouseholdUid:tokenInfo.Uid,
  110. }
  111. rpcRsp, err := pb.Garden.EventList(ctx, rpcReq)
  112. if err != nil {
  113. s, _ := json.MarshalToString(req)
  114. logger.Error("func",
  115. zap.String("call", "pb.Garden.EventList"),
  116. zap.String("params", s),
  117. zap.String("error", err.Error()))
  118. return errors.ErrorTransForm(err)
  119. }
  120. if rpcRsp.List == nil {
  121. rpcRsp.List = make([]*v1.EventItem, 0)
  122. }
  123. resp.Data = *rpcRsp
  124. ctx.JSON(http.StatusOK, resp)
  125. return nil
  126. }
  127. // 执行任务
  128. httptasker.Exec(ctx, parseParamTask, handleServiceTask)
  129. }