mirror of https://github.com/ErsatzTV/ErsatzTV.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
997 B
26 lines
997 B
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); |
|
} |
|
}
|
|
|