package v1 import ( "git.getensh.com/common/gopkgs/logger" "git.getensh.com/common/gopkgs/tasker/httptasker" "git.getensh.com/common/gopkgs/util" "github.com/gin-gonic/gin" "go.uber.org/zap" "net/http" "property-household-gateway/errors" param_v1 "property-household-gateway/param/v1" "property-household-gateway/pb" "property-household-gateway/pb/v1" "property-household-gateway/utils" ) // // @Summary 社区活动报名 // @Description 添加社区活动报名 // @Tags 社区活动 // @Accept json // @Produce json // @Param token header string true "token" // @Param body body v1.EventSignAddBody true "信息" // @Success 200 {object} v1.EventSignAddResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/event/sign [post] func (c *Controller) EventSignAdd(ctx *gin.Context) { // 解析参数 req := ¶m_v1.EventSignAddRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, nil, &req.EventSignAddBody) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.EventSignAddResponse{} rpcReq := &v1.EventSignAddRequest{ GardenId:req.GardenId, EventId:req.EventId, HouseholdUid:tokenInfo.Uid, Phone:req.Phone, Name:req.Name, Comment:req.Comment, Count:req.Count, } _, err = pb.Garden.EventSignAdd(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.EventSignAdd"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) } // // @Summary 社区活动列表 // @Description 社区活动列表 // @Tags 社区活动 // @Accept json // @Produce json // @Param token header string true "token" // @Param page query int false " " // @Param page_size query int false " " // @Param garden_id query int true " " // @Success 200 {object} v1.EventListResponse // @Failure 500 {object} base.HTTPError // @Router /api/v1/service/event [get] func (c *Controller) EventList(ctx *gin.Context) { // 解析参数 req := ¶m_v1.EventListRequest{} parseParamTask := func() error { err := util.ShouldBind(ctx, &req.Header, nil, &req.EventListQuery, nil) if err != nil { logger.Error("func", zap.String("call", "util.ShouldBind"), zap.String("error", err.Error())) return errors.ParamsError } return nil } // 业务处理 handleServiceTask := func() error { tokenInfo, err := utils.GetJwtTokenInfo(ctx) if err != nil { return err } // 响应数据 resp := param_v1.EventListResponse{} rpcReq := &v1.EventListRequest{ GardenId:req.GardenId, PageSize:req.PageSize, Page:req.Page, HouseholdUid:tokenInfo.Uid, } rpcRsp, err := pb.Garden.EventList(ctx, rpcReq) if err != nil { s, _ := json.MarshalToString(req) logger.Error("func", zap.String("call", "pb.Garden.EventList"), zap.String("params", s), zap.String("error", err.Error())) return errors.ErrorTransForm(err) } if rpcRsp.List == nil { rpcRsp.List = make([]*v1.EventItem, 0) } resp.Data = *rpcRsp ctx.JSON(http.StatusOK, resp) return nil } // 执行任务 httptasker.Exec(ctx, parseParamTask, handleServiceTask) }