* fix validation in new form layout * pin mediatr to last oss version * update dependencies * cleanup code in core * cleanup code in ffmpeg * cleanup code in infra * cleanup code in scanner * cleanup code in application * cleanup main code * cleanup test code * solution-wide code cleanup
34 lines
1.3 KiB
C#
34 lines
1.3 KiB
C#
using ErsatzTV.Core.Domain;
|
|
using ErsatzTV.Core.Interfaces.Repositories;
|
|
using static ErsatzTV.Application.Libraries.Mapper;
|
|
|
|
namespace ErsatzTV.Application.Libraries;
|
|
|
|
public class GetConfiguredLibrariesHandler : IRequestHandler<GetConfiguredLibraries, List<LibraryViewModel>>
|
|
{
|
|
private readonly ILibraryRepository _libraryRepository;
|
|
|
|
public GetConfiguredLibrariesHandler(ILibraryRepository libraryRepository) =>
|
|
_libraryRepository = libraryRepository;
|
|
|
|
public Task<List<LibraryViewModel>> Handle(
|
|
GetConfiguredLibraries request,
|
|
CancellationToken cancellationToken) =>
|
|
_libraryRepository.GetAll()
|
|
.Map(list => list.Filter(ShouldIncludeLibrary)
|
|
.OrderBy(l => l.MediaSource is LocalMediaSource ? 0 : 1)
|
|
.ThenBy(l => l.GetType().Name)
|
|
.ThenBy(l => l.MediaKind)
|
|
.Map(ProjectToViewModel).ToList());
|
|
|
|
private static bool ShouldIncludeLibrary(Library library) =>
|
|
library switch
|
|
{
|
|
LocalLibrary => library.Paths.Count > 0,
|
|
PlexLibrary plex => plex.ShouldSyncItems,
|
|
JellyfinLibrary jellyfin => jellyfin.ShouldSyncItems,
|
|
EmbyLibrary emby => emby.ShouldSyncItems,
|
|
_ => false
|
|
};
|
|
}
|