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,59 @@
package handlers
import (
"net/http"
"galaxy/gamemaster/internal/domain/operation"
"galaxy/gamemaster/internal/service/adminpatch"
)
// patchRuntimeRequestBody mirrors the OpenAPI PatchRuntimeRequest
// schema.
type patchRuntimeRequestBody struct {
Version string `json:"version"`
}
// newPatchRuntimeHandler returns the handler for
// `POST /api/v1/internal/runtimes/{game_id}/patch`.
func newPatchRuntimeHandler(deps Dependencies) http.HandlerFunc {
logger := loggerFor(deps.Logger, "internal_rest.patch_runtime")
return func(writer http.ResponseWriter, request *http.Request) {
if deps.PatchRuntime == nil {
writeError(writer, http.StatusInternalServerError, errorCodeInternal, "patch runtime service is not wired")
return
}
gameID, ok := extractGameID(writer, request)
if !ok {
return
}
var body patchRuntimeRequestBody
if err := decodeStrictJSON(request.Body, &body); err != nil {
writeError(writer, http.StatusBadRequest, errorCodeInvalidRequest, err.Error())
return
}
result, err := deps.PatchRuntime.Handle(request.Context(), adminpatch.Input{
GameID: gameID,
Version: body.Version,
OpSource: resolveOpSource(request),
SourceRef: requestSourceRef(request),
})
if err != nil {
logger.ErrorContext(request.Context(), "patch runtime service errored",
"game_id", gameID,
"err", err.Error(),
)
writeError(writer, http.StatusInternalServerError, errorCodeInternal, "patch runtime service failed")
return
}
if result.Outcome == operation.OutcomeFailure {
writeFailure(writer, result.ErrorCode, result.ErrorMessage)
return
}
writeJSON(writer, http.StatusOK, encodeRuntimeRecord(result.Record))
}
}