diff --git a/src/NzbDrone.Core/Validation/DownloadClientExistsValidator.cs b/src/NzbDrone.Core/Validation/DownloadClientExistsValidator.cs new file mode 100644 index 000000000..cf021f464 --- /dev/null +++ b/src/NzbDrone.Core/Validation/DownloadClientExistsValidator.cs @@ -0,0 +1,27 @@ +using FluentValidation.Validators; +using NzbDrone.Core.Download; + +namespace NzbDrone.Core.Validation +{ + public class DownloadClientExistsValidator : PropertyValidator + { + private readonly IDownloadClientFactory _downloadClientFactory; + + public DownloadClientExistsValidator(IDownloadClientFactory downloadClientFactory) + { + _downloadClientFactory = downloadClientFactory; + } + + protected override string GetDefaultMessageTemplate() => "Download Client does not exist"; + + protected override bool IsValid(PropertyValidatorContext context) + { + if (context?.PropertyValue == null || (int)context.PropertyValue == 0) + { + return true; + } + + return _downloadClientFactory.Exists((int)context.PropertyValue); + } + } +} diff --git a/src/Radarr.Api.V3/Indexers/IndexerController.cs b/src/Radarr.Api.V3/Indexers/IndexerController.cs index c4670b34b..883302113 100644 --- a/src/Radarr.Api.V3/Indexers/IndexerController.cs +++ b/src/Radarr.Api.V3/Indexers/IndexerController.cs @@ -1,4 +1,5 @@ using NzbDrone.Core.Indexers; +using NzbDrone.Core.Validation; using Radarr.Http; namespace Radarr.Api.V3.Indexers @@ -9,9 +10,10 @@ public class IndexerController : ProviderControllerBase c.DownloadClientId).SetValidator(downloadClientExistsValidator); } } }