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,43 @@
package handlers
import (
"errors"
"net/http"
"galaxy/gamemaster/internal/domain/runtime"
)
// newGetRuntimeHandler returns the handler for
// `GET /api/v1/internal/runtimes/{game_id}`. Reads from
// `RuntimeRecordsReader.Get` and translates `runtime.ErrNotFound` to
// `404 runtime_not_found`.
func newGetRuntimeHandler(deps Dependencies) http.HandlerFunc {
logger := loggerFor(deps.Logger, "internal_rest.get_runtime")
return func(writer http.ResponseWriter, request *http.Request) {
if deps.RuntimeRecords == nil {
writeError(writer, http.StatusInternalServerError, errorCodeInternal, "runtime records store is not wired")
return
}
gameID, ok := extractGameID(writer, request)
if !ok {
return
}
record, err := deps.RuntimeRecords.Get(request.Context(), gameID)
if err != nil {
if errors.Is(err, runtime.ErrNotFound) {
writeError(writer, http.StatusNotFound, errorCodeRuntimeNotFound, "runtime not found")
return
}
logger.ErrorContext(request.Context(), "get runtime record failed",
"game_id", gameID,
"err", err.Error(),
)
writeError(writer, http.StatusInternalServerError, errorCodeInternal, "failed to read runtime record")
return
}
writeJSON(writer, http.StatusOK, encodeRuntimeRecord(record))
}
}