15d35f6f1f
Engine no longer mints its own game UUID. The orchestrator (backend)
generates the game UUID at game-create time and passes it in the
admin/init request body as the required `gameId` field, so the value
that names the engine container and host bind-mount directory also
ends up inside the engine's state.json.
The engine rejects the zero UUID with 400 and any init that conflicts
with an existing state.json with 409 (a second init on the same gameId
is also a conflict; full idempotency is not part of the contract).
Updates rest.InitRequest, openapi.yaml (schema + 409 response),
controller.GenerateGame/NewGame/buildGameOnMap signatures, the engine
HTTP handler/executor, the backend runtime worker, and the relevant
unit and contract tests. Documentation in game/README.md,
docs/ARCHITECTURE.md, backend/README.md, and backend/docs/{runtime,flows}.md
is updated in the same patch.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
42 lines
829 B
Go
42 lines
829 B
Go
package handler
|
|
|
|
import (
|
|
"errors"
|
|
"net/http"
|
|
|
|
"galaxy/game/internal/controller"
|
|
"galaxy/model/rest"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func InitHandler(c *gin.Context, executor CommandExecutor) {
|
|
var init rest.InitRequest
|
|
if errorResponse(c, c.ShouldBindJSON(&init)) {
|
|
return
|
|
}
|
|
if init.GameID == uuid.Nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": controller.ErrGameInitNilUUID.Error()})
|
|
return
|
|
}
|
|
|
|
races := make([]string, len(init.Races))
|
|
for i := range init.Races {
|
|
races[i] = init.Races[i].RaceName
|
|
}
|
|
|
|
s, err := executor.GenerateGame(init.GameID, races)
|
|
if err != nil {
|
|
if errors.Is(err, controller.ErrGameAlreadyInit) {
|
|
c.JSON(http.StatusConflict, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
if errorResponse(c, err) {
|
|
return
|
|
}
|
|
}
|
|
|
|
c.JSON(http.StatusCreated, s)
|
|
}
|