fix: game order api & tests
This commit is contained in:
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user