Add Single-Calc for player name. Refactor admin+single-calc dialogs.
This commit is contained in:
@@ -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!")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user