38 lines
1.2 KiB
C#
38 lines
1.2 KiB
C#
using Backend.Common;
|
|
using Backend.Contracts;
|
|
using Backend.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Backend.Endpoints;
|
|
|
|
public static partial class PublicEndpoints
|
|
{
|
|
private static async Task<IResult> GetWinnerArchive(int year, AwardsDbContext db)
|
|
{
|
|
var winnerRows = await db.Results
|
|
.AsNoTracking()
|
|
.Include(result => result.Candidate)
|
|
.Where(result => result.Season.Year == year)
|
|
.OrderBy(result => result.CategoryName)
|
|
.Select(result => new
|
|
{
|
|
result.CategoryName,
|
|
WinnerName = result.Candidate.DisplayName,
|
|
WinnerSlug = result.Candidate.ChannelSlug,
|
|
WinnerPlatform = result.Candidate.Platform,
|
|
})
|
|
.ToArrayAsync();
|
|
|
|
var items = winnerRows
|
|
.Select(result => new WinnerArchiveItemDto(
|
|
result.CategoryName,
|
|
result.WinnerName,
|
|
result.WinnerSlug,
|
|
result.WinnerPlatform,
|
|
SeasonMappings.BuildProfileUrl(result.WinnerPlatform, result.WinnerSlug)))
|
|
.ToArray();
|
|
|
|
return Results.Ok(new WinnerArchiveResponse(year, items));
|
|
}
|
|
}
|