Files
ersatztv/ErsatzTV.Application/Plex/Queries/GetPlexLibrariesBySourceIdHandler.cs
T
Jason DoveandGitHub 245c4ec359 code analysis and cleanup (#1411)
* cleanup scanner project

* cleanup infrastructure projects

* cleanup ffmpeg project

* cleanup core project

* cleanup app project

* cleanup main project

* update dependencies

* code cleanup
2023-09-03 06:23:42 -05:00

27 lines
997 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)
.Map(pl => ProjectToViewModel(pl))
.ToListAsync(cancellationToken);
}
}