private async Task SynchronizeAdminUserId( SynchronizeJellyfinAdminUserId 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 admin user id for source {MediaSourceId}", request.JellyfinMediaSourceId), error => _logger.LogWarning( "Unable to synchronize Jellyfin admin user id for source {MediaSourceId}: {Error}", request.JellyfinMediaSourceId, error.Value)); }
private Task <Validation <BaseError, JellyfinMediaSource> > MediaSourceMustExist( SynchronizeJellyfinAdminUserId request) => _mediaSourceRepository.GetJellyfin(request.JellyfinMediaSourceId) .Map(o => o.ToValidation <BaseError>("Jellyfin media source does not exist."));
private Task <Validation <BaseError, ConnectionParameters> > Validate(SynchronizeJellyfinAdminUserId request) => MediaSourceMustExist(request) .BindT(MediaSourceMustHaveActiveConnection) .BindT(MediaSourceMustHaveApiKey);
public Task <Either <BaseError, Unit> > Handle( SynchronizeJellyfinAdminUserId request, CancellationToken cancellationToken) => Validate(request) .Map(v => v.ToEither <ConnectionParameters>()) .BindT(PerformSync);