private async Task SynchronizeLibraries( SynchronizeJellyfinLibraries 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.LogInformation( "Successfully synchronized Jellyfin libraries for source {MediaSourceId}", request.JellyfinMediaSourceId), error => _logger.LogWarning( "Unable to synchronize Jellyfin libraries for source {MediaSourceId}: {Error}", request.JellyfinMediaSourceId, error.Value)); }
private Task <Validation <BaseError, JellyfinMediaSource> > MediaSourceMustExist( SynchronizeJellyfinLibraries request) => _mediaSourceRepository.GetJellyfin(request.JellyfinMediaSourceId) .Map(o => o.ToValidation <BaseError>("Jellyfin media source does not exist."));
private Task <Validation <BaseError, ConnectionParameters> > Validate(SynchronizeJellyfinLibraries request) => MediaSourceMustExist(request) .BindT(MediaSourceMustHaveActiveConnection) .BindT(MediaSourceMustHaveApiKey);
public Task <Either <BaseError, Unit> > Handle( SynchronizeJellyfinLibraries request, CancellationToken cancellationToken) => Validate(request) .MapT(SynchronizeLibraries) .Bind(v => v.ToEitherAsync());