package app import ( "net/http" "strconv" "bindbox-game/internal/code" "bindbox-game/internal/pkg/core" thresholdsvc "bindbox-game/internal/service/threshold_activity" ) type listThresholdActivitiesRequest struct { Type string `form:"type"` Status string `form:"status"` Page int `form:"page"` PageSize int `form:"page_size"` } type listThresholdParticipantsRequest struct { Page int `form:"page"` PageSize int `form:"page_size"` } type listThresholdWinnersRequest struct { Page int `form:"page"` PageSize int `form:"page_size"` } func (h *handler) ListThresholdActivities() core.HandlerFunc { return func(ctx core.Context) { req := new(listThresholdActivitiesRequest) if err := ctx.ShouldBindForm(req); err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, err.Error())) return } status := req.Status if status == "" { status = thresholdsvc.StatusActive } res, err := h.threshold.ListActivities(ctx.RequestContext(), thresholdsvc.ListActivitiesRequest{Type: req.Type, Status: status, Page: req.Page, PageSize: req.PageSize}) if err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ListActivitiesError, err.Error())) return } ctx.Payload(res) } } func (h *handler) GetThresholdActivity() core.HandlerFunc { return func(ctx core.Context) { id, err := strconv.ParseInt(ctx.Param("id"), 10, 64) if err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "活动ID无效")) return } userID := int64(ctx.SessionUserInfo().Id) res, err := h.threshold.GetActivity(ctx.RequestContext(), id, userID) if err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.GetActivityError, err.Error())) return } ctx.Payload(res) } } func (h *handler) JoinThresholdActivity() core.HandlerFunc { return func(ctx core.Context) { id, err := strconv.ParseInt(ctx.Param("id"), 10, 64) if err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "活动ID无效")) return } info := ctx.SessionUserInfo() userID := int64(info.Id) if userID <= 0 { ctx.AbortWithError(core.Error(http.StatusUnauthorized, code.AuthorizationError, "请先登录")) return } if err := h.threshold.Join(ctx.RequestContext(), id, userID); err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ModifyActivityError, err.Error())) return } ctx.Payload(map[string]string{"message": "参与成功"}) } } func (h *handler) ListThresholdParticipants() core.HandlerFunc { return func(ctx core.Context) { id, _ := strconv.ParseInt(ctx.Param("id"), 10, 64) req := new(listThresholdParticipantsRequest) if err := ctx.ShouldBindForm(req); err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, err.Error())) return } res, err := h.threshold.ListParticipants(ctx.RequestContext(), id, req.Page, req.PageSize) if err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ListActivitiesError, err.Error())) return } ctx.Payload(res) } } func (h *handler) ListThresholdWinners() core.HandlerFunc { return func(ctx core.Context) { id, _ := strconv.ParseInt(ctx.Param("id"), 10, 64) req := new(listThresholdWinnersRequest) if err := ctx.ShouldBindForm(req); err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, err.Error())) return } res, err := h.threshold.ListWinners(ctx.RequestContext(), id, req.Page, req.PageSize) if err != nil { ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ListActivitiesError, err.Error())) return } ctx.Payload(res) } }