fix: game order api & tests

This commit is contained in:
Ilia Denisov
2026-05-09 10:55:55 +02:00
parent 2a1e80053a
commit 381e41b325
6 changed files with 361 additions and 16 deletions
+7 -8
View File
@@ -46,23 +46,22 @@ type orderParam struct {
func GetOrderHandler(c *gin.Context, executor CommandExecutor) {
p := &orderParam{}
err := c.ShouldBindQuery(p)
if errorResponse(c, err) {
// ShouldBindQuery surfaces both validator failures and strconv parse
// errors; both are client-side faults, so 400 is the correct mapping.
if err := c.ShouldBindQuery(p); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}
order, ok, err := executor.FetchOrder(p.Player, uint(p.Turn))
o, ok, err := executor.FetchOrder(p.Player, uint(p.Turn))
if errorResponse(c, err) {
return
}
if !ok {
// there was no order previously sent by player
// no order has been previously stored by the player for this turn
c.Status(http.StatusNoContent)
}
var cmd rest.Command
if errorResponse(c, c.ShouldBindJSON(&cmd)) {
return
}
c.JSON(http.StatusOK, order)
c.JSON(http.StatusOK, o)
}