Files
cms-server/api/stats/global.go
Asai Neko 2f3eaf17ea
All checks were successful
Server Check Build (NixCN CMS) TeamCity build finished
Add agenda and stats and event management service with api
Signed-off-by: Asai Neko <sugar@sne.moe>
2026-03-26 16:15:07 +08:00

45 lines
1.3 KiB
Go

package stats
import (
"nixcn-cms/internal/exception"
"nixcn-cms/service/service_stats"
"nixcn-cms/tracer"
"nixcn-cms/utils"
"github.com/gin-gonic/gin"
)
// Global returns platform-wide statistics. Lv40+ only.
//
// @Summary Global Stats
// @Description Returns total users, user counts per permission_level, and per-event join/checkin counts.
// @Tags Stats
// @Produce json
// @Security Bearer
// @Success 200 {object} utils.RespStatus{data=service_stats.GlobalStatsResponse}
// @Failure 401 {object} utils.RespStatus{data=nil} "Unauthorized"
// @Failure 500 {object} utils.RespStatus{data=nil} "Internal Server Error"
// @Router /stats/global [get]
func (self *StatsHandler) Global(c *gin.Context) {
ctx, span := tracer.StartSpan(
c.Request.Context(),
"api_stats",
"global",
)
defer span.End()
ctx = exception.ContextWithEndpoint(ctx, exception.EndpointStatsGlobal)
ctx = exception.ContextWithService(ctx, exception.ServiceEndpoint)
result := self.svc.Global(&service_stats.GlobalStatsPayload{
Context: ctx,
})
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)
}