Refactor WebGateway state classes and tuple usage

This commit is contained in:
Jacob Schmidt 2026-02-27 19:51:31 -06:00
parent 0dde7c40f3
commit 29e027b918

View File

@ -67,11 +67,11 @@ app.MapPost("/api/command", async (CommandEnvelope? command, Entry entry) =>
app.MapGet("/api/sidecar/root", (SidecarRootState rootState) =>
{
var snapshot = rootState.Get();
var (root, isCustom) = rootState.Get();
return Results.Ok(new
{
root = snapshot.Root,
isCustom = snapshot.IsCustom
root,
isCustom
});
});
@ -84,12 +84,12 @@ app.MapPost("/api/sidecar/root", (SetSidecarRootRequest? request, SidecarRootSta
}
rootState.Set(path);
var snapshot = rootState.Get();
Environment.SetEnvironmentVariable("JOURNAL_PROJECT_ROOT", snapshot.Root);
var (root, isCustom) = rootState.Get();
Environment.SetEnvironmentVariable("JOURNAL_PROJECT_ROOT", root);
return Results.Ok(new
{
root = snapshot.Root,
isCustom = snapshot.IsCustom
root,
isCustom
});
});
@ -207,32 +207,20 @@ string ResolveWebDist(string repoRootPath)
string ErrorResponse(string message)
=> JsonSerializer.Serialize(new { ok = false, error = message }, gatewayJsonOptions);
sealed class WebUiState
sealed class WebUiState(string distPath)
{
public WebUiState(string distPath)
{
DistPath = distPath;
}
public string DistPath { get; }
public string DistPath { get; } = distPath;
public bool Exists => Directory.Exists(DistPath) && File.Exists(Path.Combine(DistPath, "index.html"));
}
sealed class SidecarRootState
sealed class SidecarRootState(string autoRoot)
{
private readonly object _sync = new();
private readonly string _autoRoot;
private string _currentRoot;
private readonly string _autoRoot = autoRoot;
private string _currentRoot = autoRoot;
private bool _isCustom;
public SidecarRootState(string autoRoot)
{
_autoRoot = autoRoot;
_currentRoot = autoRoot;
_isCustom = false;
}
public (string Root, bool IsCustom) Get()
{
lock (_sync)
@ -272,5 +260,3 @@ sealed class CommandEnvelope
public string? Tag { get; set; }
public JsonElement? Payload { get; set; }
}