From 70b5dd39843b6a4193967ba7702f9ccd488f5583 Mon Sep 17 00:00:00 2001 From: Warp Date: Sat, 21 Feb 2026 10:43:56 +0100 Subject: [PATCH] add /v2/score/:id --- cmd/api/server.go | 2 ++ handlers/scoreboard.go | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/cmd/api/server.go b/cmd/api/server.go index 4dca331..518fbd1 100644 --- a/cmd/api/server.go +++ b/cmd/api/server.go @@ -185,6 +185,8 @@ func initializeRoutes(engine *gin.Engine) { engine.GET("/v2/leaderboard/clans", handlers.CreateHandler(handlers.GetClanLeaderboard)) // Scores + engine.GET("/v2/score/:id", middleware.AllowAuth, handlers.CreateHandler(handlers.GetScoreById)) + engine.GET("/v2/scores/:md5/stats", middleware.RequireAuth, handlers.CreateHandler(handlers.GetVirtualReplayPlayerOutput)) engine.GET("/v2/scores/:md5/global", middleware.AllowAuth, handlers.CreateHandler(handlers.GetGlobalScoresForMap)) diff --git a/handlers/scoreboard.go b/handlers/scoreboard.go index 5d01f7a..119559d 100644 --- a/handlers/scoreboard.go +++ b/handlers/scoreboard.go @@ -13,6 +13,27 @@ const ( MaxNormalScoreboardLimit int = 50 ) +func GetScoreById(c *gin.Context) *APIError { + id, err := strconv.Atoi(c.Param("id")) + + if err != nil { + return APIErrorBadRequest("Invalid id") + } + + score, err := db.GetScoreById(id) + + if err != nil && err != gorm.ErrRecordNotFound { + return APIErrorServerError("Error getting score by id", err) + } + + if score == nil { + return APIErrorNotFound("Score") + } + + c.JSON(http.StatusOK, gin.H{"score": score}) + return nil +} + // GetGlobalScoresForMap Retrieves the global scoreboard for a given map. // Endpoint: GET: /v2/scores/:md5/global func GetGlobalScoresForMap(c *gin.Context) *APIError {