using ErsatzTV.Infrastructure.Data; using Microsoft.EntityFrameworkCore; using static ErsatzTV.Application.Plex.Mapper; namespace ErsatzTV.Application.Plex; public class GetPlexLibrariesBySourceIdHandler : IRequestHandler> { private readonly IDbContextFactory _dbContextFactory; public GetPlexLibrariesBySourceIdHandler(IDbContextFactory dbContextFactory) => _dbContextFactory = dbContextFactory; public async Task> Handle( GetPlexLibrariesBySourceId request, CancellationToken cancellationToken) { await using TvContext context = await _dbContextFactory.CreateDbContextAsync(cancellationToken); return await context.PlexLibraries .AsNoTracking() .Where(l => l.MediaSourceId == request.PlexMediaSourceId) .Map(pl => ProjectToViewModel(pl)) .ToListAsync(cancellationToken); } }