using ErsatzTV.Core.Domain; using ErsatzTV.Infrastructure.Data; using ErsatzTV.Infrastructure.Extensions; using Microsoft.EntityFrameworkCore; namespace ErsatzTV.Application.Channels; public class GetChannelResolutionHandler(IDbContextFactory dbContextFactory) : IRequestHandler> { public async Task> Handle( GetChannelResolution request, CancellationToken cancellationToken) { await using TvContext dbContext = await dbContextFactory.CreateDbContextAsync(cancellationToken); Option maybeChannel = await dbContext.Channels .AsNoTracking() .Include(c => c.FFmpegProfile) .ThenInclude(ff => ff.Resolution) .SelectOneAsync(c => c.Number, c => c.Number == request.ChannelNumber); return maybeChannel.Map(c => Mapper.ProjectToViewModel(c.FFmpegProfile.Resolution)); } }