package event import ( "errors" "nixcn-cms/internal/exception" "nixcn-cms/service/service_event" "nixcn-cms/tracer" "nixcn-cms/utils" "github.com/gin-gonic/gin" "github.com/google/uuid" ) // Stats returns aggregate statistics for an event. // // @Summary Get Event Statistics // @Description Returns join count, checkin count, KYC pass rate, and agenda submission count. Only accessible by the event owner (Manager). // @Tags Event // @Produce json // @Security Bearer // @Param event_id query string true "Event UUID" // @Success 200 {object} utils.RespStatus{data=service_event.EventStatsResponse} "Statistics retrieved successfully" // @Failure 400 {object} utils.RespStatus{data=nil} "Invalid Input" // @Failure 401 {object} utils.RespStatus{data=nil} "Unauthorized" // @Failure 403 {object} utils.RespStatus{data=nil} "Not Event Owner" // @Failure 404 {object} utils.RespStatus{data=nil} "Event Not Found" // @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error" // @Router /event/stats [get] func (self *EventHandler) Stats(c *gin.Context) { ctx, span := tracer.StartSpan( c.Request.Context(), "api_event", "stats", ) defer span.End() ctx = exception.ContextWithEndpoint(ctx, exception.EndpointEventStats) ctx = exception.ContextWithService(ctx, exception.ServiceEndpoint) userIdOrig, ok := c.Get("user_id") if !ok { errorCode := exception.New( exception.WithStatus(exception.StatusUser), exception.WithType(exception.TypeCommon), exception.WithOriginal(exception.CommonErrorMissingUserId), exception.WithError(errors.New("Missing UserId")), ).Throw(ctx).String() utils.HttpResponse(c, 403, errorCode) return } userId, err := uuid.Parse(userIdOrig.(string)) if err != nil { errorCode := exception.New( exception.WithStatus(exception.StatusServer), exception.WithType(exception.TypeCommon), exception.WithOriginal(exception.CommonErrorUuidParseFailed), exception.WithError(err), ).Throw(ctx).String() utils.HttpResponse(c, 500, errorCode) return } result := self.svc.Stats(&service_event.EventStatsPayload{ Context: ctx, UserId: userId, Data: &service_event.EventStatsData{ EventId: c.Query("event_id"), }, }) if result.Common.Exception.Original != exception.CommonSuccess { utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String()) return } utils.HttpResponse(c, result.Common.HttpCode, result.Common.Exception.String(), result.Data) }