C# formatting
This commit is contained in:
@@ -15,7 +15,9 @@ public static class StateEndpoints
|
||||
group.MapGet("/state", async (HttpContext ctx, AppDbContext db) =>
|
||||
{
|
||||
var player = await EndpointHelpers.GetAuthenticatedPlayer(ctx, db);
|
||||
if (player is null) return Results.Unauthorized();
|
||||
if (player is null)
|
||||
return Results.Unauthorized();
|
||||
|
||||
var phase = await EndpointHelpers.GetPhase(db, player.Id);
|
||||
|
||||
var state = await db.AppState.AsNoTracking().FirstAsync();
|
||||
@@ -36,16 +38,27 @@ public static class StateEndpoints
|
||||
group.MapGet("/me", async (HttpContext ctx, AppDbContext db) =>
|
||||
{
|
||||
var player = await EndpointHelpers.GetAuthenticatedPlayer(ctx, db);
|
||||
if (player is null) return Results.Unauthorized();
|
||||
if (player is null)
|
||||
return Results.Unauthorized();
|
||||
|
||||
var phase = await EndpointHelpers.GetPhase(db, player.Id);
|
||||
return Results.Ok(new { player.Id, player.DisplayName, player.Username, player.IsAdmin, CurrentPhase = phase, player.VotesFinal, player.HasJoker });
|
||||
return Results.Ok(new
|
||||
{
|
||||
player.Id,
|
||||
player.DisplayName,
|
||||
player.Username,
|
||||
player.IsAdmin,
|
||||
CurrentPhase = phase,
|
||||
player.VotesFinal,
|
||||
player.HasJoker
|
||||
});
|
||||
});
|
||||
|
||||
group.MapPost("/me/phase/next", async (HttpContext ctx, AppDbContext db, IConfiguration config) =>
|
||||
group.MapPost("/me/phase/next", async (HttpContext ctx, AppDbContext db, IConfiguration _) =>
|
||||
{
|
||||
var player = await EndpointHelpers.GetAuthenticatedPlayer(ctx, db);
|
||||
if (player is null) return Results.Unauthorized();
|
||||
var isAdmin = await EndpointHelpers.IsAdmin(ctx, db);
|
||||
if (player is null)
|
||||
return Results.Unauthorized();
|
||||
|
||||
var next = NextPhase(player.CurrentPhase);
|
||||
var appState = await db.AppState.FirstAsync();
|
||||
@@ -58,13 +71,19 @@ public static class StateEndpoints
|
||||
player.CurrentPhase = next;
|
||||
player.VotesFinal = false; // moving forward clears any prior finalize
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(new { player.CurrentPhase, appState.ResultsOpen });
|
||||
return Results.Ok(new
|
||||
{
|
||||
player.CurrentPhase,
|
||||
appState.ResultsOpen
|
||||
});
|
||||
});
|
||||
|
||||
group.MapPost("/me/phase/prev", async (HttpContext ctx, AppDbContext db, IConfiguration config) =>
|
||||
group.MapPost("/me/phase/prev", async (HttpContext ctx, AppDbContext db, IConfiguration _) =>
|
||||
{
|
||||
var player = await EndpointHelpers.GetAuthenticatedPlayer(ctx, db);
|
||||
if (player is null) return Results.Unauthorized();
|
||||
if (player is null)
|
||||
return Results.Unauthorized();
|
||||
|
||||
var isAdmin = await EndpointHelpers.IsAdmin(ctx, db);
|
||||
if (!isAdmin)
|
||||
{
|
||||
@@ -75,12 +94,16 @@ public static class StateEndpoints
|
||||
player.VotesFinal = false;
|
||||
await db.SaveChangesAsync();
|
||||
var appState = await db.AppState.AsNoTracking().FirstAsync();
|
||||
return Results.Ok(new { player.CurrentPhase, appState.ResultsOpen });
|
||||
return Results.Ok(new
|
||||
{
|
||||
player.CurrentPhase,
|
||||
appState.ResultsOpen
|
||||
});
|
||||
});
|
||||
|
||||
group.MapPost("/me/name", async ([FromBody] SetNameRequest request, HttpContext ctx, AppDbContext db) =>
|
||||
{
|
||||
if (request.Name?.Trim().Length > 16)
|
||||
if (request.Name.Trim().Length > 16)
|
||||
{
|
||||
return Results.BadRequest(new { error = "Name is required and must be <= 16 characters." });
|
||||
}
|
||||
@@ -92,27 +115,32 @@ public static class StateEndpoints
|
||||
}
|
||||
|
||||
var player = await EndpointHelpers.GetAuthenticatedPlayer(ctx, db);
|
||||
if (player is null) return Results.Unauthorized();
|
||||
if (player is null)
|
||||
return Results.Unauthorized();
|
||||
|
||||
player.DisplayName = name;
|
||||
await db.SaveChangesAsync();
|
||||
return Results.Ok(new { player.Id, player.DisplayName });
|
||||
return Results.Ok(new
|
||||
{
|
||||
player.Id,
|
||||
player.DisplayName
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private static Phase NextPhase(Phase current) => current switch
|
||||
{
|
||||
Phase.Suggest => Phase.Vote,
|
||||
Phase.Reveal => Phase.Vote, // legacy safety
|
||||
Phase.Vote => Phase.Results,
|
||||
_ => Phase.Results
|
||||
Phase.Reveal => Phase.Vote, // legacy safety
|
||||
Phase.Vote => Phase.Results,
|
||||
_ => Phase.Results
|
||||
};
|
||||
|
||||
private static Phase PrevPhase(Phase current) => current switch
|
||||
{
|
||||
Phase.Results => Phase.Vote,
|
||||
Phase.Vote => Phase.Suggest,
|
||||
Phase.Reveal => Phase.Suggest, // legacy safety
|
||||
_ => Phase.Suggest
|
||||
Phase.Vote => Phase.Suggest,
|
||||
Phase.Reveal => Phase.Suggest, // legacy safety
|
||||
_ => Phase.Suggest
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user