Add Single-Calc for player name. Refactor admin+single-calc dialogs.

This commit is contained in:
MaxJa4
2024-01-21 12:12:47 +01:00
parent 4ff139b217
commit 8edbbb4347
6 changed files with 132 additions and 47 deletions

View File

@@ -123,3 +123,23 @@ func GetScoreByPlayerID(c *gin.Context) {
c.JSON(http.StatusBadRequest, "Invalid request!")
}
}
// GetScoreByPlayerName POST /score/:player_name
func GetScoreByPlayerName(c *gin.Context) {
playerName := c.Param("player_name")
game, err := GetActiveGame(c)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "No active game available!"})
return
}
score := utils.CalcPlayerScore(playerName, game.Tag)
if score != score || score == -1 { // NaN
c.String(http.StatusNotFound, "Spieler nicht gefunden!")
} else if score != -1 {
c.String(http.StatusOK, fmt.Sprintf("%.2f", score))
} else {
c.String(http.StatusBadRequest, "Ungültige Abfrage!")
}
}