Untrusted draft — no build/test had run yet. Review before building on it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
28 lines
1.1 KiB
C#
28 lines
1.1 KiB
C#
using ErsatzTV.Core.Api.Graphics;
|
|
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Infrastructure.Data;
|
|
using Microsoft.EntityFrameworkCore;
|
|
using static ErsatzTV.Application.Graphics.Mapper;
|
|
|
|
namespace ErsatzTV.Application.Graphics;
|
|
|
|
public class GetAllGraphicsElementsForApiHandler(IDbContextFactory<TvContext> dbContextFactory)
|
|
: IRequestHandler<GetAllGraphicsElementsForApi, List<GraphicsElementResponseModel>>
|
|
{
|
|
public async Task<List<GraphicsElementResponseModel>> Handle(
|
|
GetAllGraphicsElementsForApi request,
|
|
CancellationToken cancellationToken)
|
|
{
|
|
await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken);
|
|
List<GraphicsElement> graphicsElements = await dbContext.GraphicsElements
|
|
.AsNoTracking()
|
|
.ToListAsync(cancellationToken);
|
|
return graphicsElements
|
|
.Map(ProjectToViewModel)
|
|
.OrderBy(e => e.Name == e.FileName)
|
|
.ThenBy(e => e.Name)
|
|
.Select(vm => new GraphicsElementResponseModel(vm.Id, vm.Name))
|
|
.ToList();
|
|
}
|
|
}
|