feat: gamemaster

This commit is contained in:
Ilia Denisov
2026-05-03 07:59:03 +02:00
committed by GitHub
parent a7cee15115
commit 3e2622757e
229 changed files with 41521 additions and 1098 deletions
@@ -0,0 +1,49 @@
package handlers
import (
"net/http"
"galaxy/gamemaster/internal/domain/operation"
"galaxy/gamemaster/internal/service/adminforce"
)
// newForceNextTurnHandler returns the handler for
// `POST /api/v1/internal/runtimes/{game_id}/force-next-turn`. The
// request has no body; the handler delegates to
// `adminforce.Service.Handle` and encodes the resulting runtime
// record on success.
func newForceNextTurnHandler(deps Dependencies) http.HandlerFunc {
logger := loggerFor(deps.Logger, "internal_rest.force_next_turn")
return func(writer http.ResponseWriter, request *http.Request) {
if deps.ForceNextTurn == nil {
writeError(writer, http.StatusInternalServerError, errorCodeInternal, "force next turn service is not wired")
return
}
gameID, ok := extractGameID(writer, request)
if !ok {
return
}
result, err := deps.ForceNextTurn.Handle(request.Context(), adminforce.Input{
GameID: gameID,
OpSource: resolveOpSource(request),
SourceRef: requestSourceRef(request),
})
if err != nil {
logger.ErrorContext(request.Context(), "force next turn service errored",
"game_id", gameID,
"err", err.Error(),
)
writeError(writer, http.StatusInternalServerError, errorCodeInternal, "force next turn service failed")
return
}
if result.Outcome == operation.OutcomeFailure {
writeFailure(writer, result.ErrorCode, result.ErrorMessage)
return
}
writeJSON(writer, http.StatusOK, encodeRuntimeRecord(result.TurnGeneration.Record))
}
}