feat: game order api methods

This commit is contained in:
Ilia Denisov
2026-05-09 10:36:44 +02:00
parent f2a7f2b515
commit 2a1e80053a
17 changed files with 166 additions and 75 deletions
+32 -3
View File
@@ -12,7 +12,7 @@ import (
"github.com/gin-gonic/gin"
)
func OrderHandler(c *gin.Context, executor CommandExecutor) {
func PutOrderHandler(c *gin.Context, executor CommandExecutor) {
var cmd rest.Command
if errorResponse(c, c.ShouldBindJSON(&cmd)) {
return
@@ -31,9 +31,38 @@ func OrderHandler(c *gin.Context, executor CommandExecutor) {
return
}
if errorResponse(c, executor.ValidateOrder(cmd.Actor, commands...)) {
result, err := executor.ValidateOrder(cmd.Actor, commands...)
if errorResponse(c, err) {
return
}
c.Status(http.StatusNoContent)
c.JSON(http.StatusAccepted, result)
}
type orderParam struct {
Player string `form:"player" binding:"required,notblank"`
Turn int `form:"turn" binding:"gte=0"`
}
func GetOrderHandler(c *gin.Context, executor CommandExecutor) {
p := &orderParam{}
err := c.ShouldBindQuery(p)
if errorResponse(c, err) {
return
}
order, ok, err := executor.FetchOrder(p.Player, uint(p.Turn))
if errorResponse(c, err) {
return
}
if !ok {
// there was no order previously sent by player
c.Status(http.StatusNoContent)
}
var cmd rest.Command
if errorResponse(c, c.ShouldBindJSON(&cmd)) {
return
}
c.JSON(http.StatusOK, order)
}