Files
ersatztv/ErsatzTV.Application/Plex/Queries/GetPlexLibrariesBySourceIdHandler.cs
T
Jason DoveandGitHub 1c07df5bc3 use cancellation tokens in many places (#2350)
* use cancellation tokens everywhere

* more cancellation tokens
2025-08-27 03:20:35 +00:00

27 lines
1015 B
C#

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