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)) } }