Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/api/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
21 changes: 21 additions & 0 deletions handlers/scoreboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down