mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* cleanup plex libraries query * show plex server names in libraries pagepull/1403/head
12 changed files with 64 additions and 30 deletions
@ -1,20 +1,28 @@ |
|||||||
using ErsatzTV.Core.Interfaces.Repositories; |
using ErsatzTV.Infrastructure.Data; |
||||||
|
using Microsoft.EntityFrameworkCore; |
||||||
using static ErsatzTV.Application.Plex.Mapper; |
using static ErsatzTV.Application.Plex.Mapper; |
||||||
|
|
||||||
namespace ErsatzTV.Application.Plex; |
namespace ErsatzTV.Application.Plex; |
||||||
|
|
||||||
public class |
public class GetPlexLibrariesBySourceIdHandler : IRequestHandler<GetPlexLibrariesBySourceId, List<PlexLibraryViewModel>> |
||||||
GetPlexLibrariesBySourceIdHandler : IRequestHandler<GetPlexLibrariesBySourceId, |
|
||||||
List<PlexLibraryViewModel>> |
|
||||||
{ |
{ |
||||||
private readonly IMediaSourceRepository _mediaSourceRepository; |
private readonly IDbContextFactory<TvContext> _dbContextFactory; |
||||||
|
|
||||||
public GetPlexLibrariesBySourceIdHandler(IMediaSourceRepository mediaSourceRepository) => |
public GetPlexLibrariesBySourceIdHandler(IDbContextFactory<TvContext> dbContextFactory) |
||||||
_mediaSourceRepository = mediaSourceRepository; |
{ |
||||||
|
_dbContextFactory = dbContextFactory; |
||||||
|
} |
||||||
|
|
||||||
public Task<List<PlexLibraryViewModel>> Handle( |
public async Task<List<PlexLibraryViewModel>> Handle( |
||||||
GetPlexLibrariesBySourceId request, |
GetPlexLibrariesBySourceId request, |
||||||
CancellationToken cancellationToken) => |
CancellationToken cancellationToken) |
||||||
_mediaSourceRepository.GetPlexLibraries(request.PlexMediaSourceId) |
{ |
||||||
.Map(list => list.Map(ProjectToViewModel).ToList()); |
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); |
||||||
|
} |
||||||
} |
} |
||||||
|
|||||||
Loading…
Reference in new issue