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.
42 lines
1.5 KiB
42 lines
1.5 KiB
using System.Collections.Generic; |
|
using System.Linq; |
|
using System.Threading; |
|
using System.Threading.Tasks; |
|
using ErsatzTV.Core; |
|
using ErsatzTV.Core.Interfaces.Repositories; |
|
using ErsatzTV.Core.Interfaces.Search; |
|
using LanguageExt; |
|
|
|
namespace ErsatzTV.Application.Plex.Commands |
|
{ |
|
public class |
|
UpdatePlexLibraryPreferencesHandler : MediatR.IRequestHandler<UpdatePlexLibraryPreferences, |
|
Either<BaseError, Unit>> |
|
{ |
|
private readonly IMediaSourceRepository _mediaSourceRepository; |
|
private readonly ISearchIndex _searchIndex; |
|
|
|
public UpdatePlexLibraryPreferencesHandler( |
|
IMediaSourceRepository mediaSourceRepository, |
|
ISearchIndex searchIndex) |
|
{ |
|
_mediaSourceRepository = mediaSourceRepository; |
|
_searchIndex = searchIndex; |
|
} |
|
|
|
public async Task<Either<BaseError, Unit>> Handle( |
|
UpdatePlexLibraryPreferences request, |
|
CancellationToken cancellationToken) |
|
{ |
|
var toDisable = request.Preferences.Filter(p => p.ShouldSyncItems == false).Map(p => p.Id).ToList(); |
|
List<int> ids = await _mediaSourceRepository.DisablePlexLibrarySync(toDisable); |
|
await _searchIndex.RemoveItems(ids); |
|
_searchIndex.Commit(); |
|
|
|
IEnumerable<int> toEnable = request.Preferences.Filter(p => p.ShouldSyncItems).Map(p => p.Id); |
|
await _mediaSourceRepository.EnablePlexLibrarySync(toEnable); |
|
|
|
return Unit.Default; |
|
} |
|
} |
|
}
|
|
|