Split API into phase-specific endpoint files

This commit is contained in:
2026-01-28 17:11:25 +01:00
parent 9363b029df
commit 983488d258
8 changed files with 405 additions and 346 deletions

View File

@@ -0,0 +1,39 @@
using GameList.Data;
using GameList.Domain;
using Microsoft.EntityFrameworkCore;
namespace GameList.Endpoints;
public static class ResultsEndpoints
{
public static void MapResultsEndpoints(this IEndpointRouteBuilder app)
{
app.MapGet("/api/results", async (AppDbContext db) =>
{
var phase = await EndpointHelpers.GetPhase(db);
if (phase != Phase.Results)
return EndpointHelpers.PhaseMismatch(Phase.Results, phase);
var results = await db.Suggestions.AsNoTracking()
.Include(s => s.Player)
.Include(s => s.Votes)
.Select(s => new
{
s.Id,
s.Name,
Author = s.Player!.DisplayName,
Total = s.Votes.Sum(v => v.Score),
Count = s.Votes.Count,
Average = s.Votes.Count == 0 ? 0 : s.Votes.Average(v => v.Score),
s.ScreenshotUrl,
s.YoutubeUrl,
s.Description,
s.Genre
})
.OrderByDescending(r => r.Total)
.ToListAsync();
return Results.Ok(results);
});
}
}