public async Task <Either <BaseError, Unit> > Handle( SynchronizeJellyfinCollections request, CancellationToken cancellationToken) { Validation <BaseError, ConnectionParameters> validation = await Validate(request); return(await validation.Match( SynchronizeCollections, error => Task.FromResult <Either <BaseError, Unit> >(error.Join()))); }
private async Task SynchronizeJellyfinCollections( SynchronizeJellyfinCollections request, CancellationToken cancellationToken) { using IServiceScope scope = _serviceScopeFactory.CreateScope(); IMediator mediator = scope.ServiceProvider.GetRequiredService <IMediator>(); Either <BaseError, Unit> result = await mediator.Send(request, cancellationToken); result.BiIter( _ => _logger.LogDebug("Done synchronizing jellyfin collections"), error => _logger.LogWarning( "Unable to synchronize jellyfin collections for source {MediaSourceId}: {Error}", request.JellyfinMediaSourceId, error.Value)); }
private Task <Validation <BaseError, JellyfinMediaSource> > MediaSourceMustExist( SynchronizeJellyfinCollections request) => _mediaSourceRepository.GetJellyfin(request.JellyfinMediaSourceId) .Map(o => o.ToValidation <BaseError>("Jellyfin media source does not exist."));
private Task <Validation <BaseError, ConnectionParameters> > Validate(SynchronizeJellyfinCollections request) => MediaSourceMustExist(request) .BindT(MediaSourceMustHaveActiveConnection) .BindT(MediaSourceMustHaveApiKey);