package handlers import ( "errors" "net/http" "galaxy/rtmanager/internal/domain/runtime" "galaxy/rtmanager/internal/service/startruntime" ) // newGetHandler returns the handler for // `GET /api/v1/internal/runtimes/{game_id}`. The handler reads // directly from the runtime record store and translates // `runtime.ErrNotFound` to `404 not_found`. Like list, it does not // run through the service layer and does not produce an operation_log // row. func newGetHandler(deps Dependencies) http.HandlerFunc { logger := loggerFor(deps.Logger, "internal_rest.get") return func(writer http.ResponseWriter, request *http.Request) { if deps.RuntimeRecords == nil { writeError(writer, http.StatusInternalServerError, startruntime.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 errors.Is(err, runtime.ErrNotFound) { writeError(writer, http.StatusNotFound, startruntime.ErrorCodeNotFound, "runtime record not found", ) return } if err != nil { logger.ErrorContext(request.Context(), "get runtime record", "game_id", gameID, "err", err.Error(), ) writeError(writer, http.StatusInternalServerError, startruntime.ErrorCodeInternal, "failed to read runtime record", ) return } writeJSON(writer, http.StatusOK, encodeRuntimeRecord(record)) } }