mirror of
https://github.com/lidarr/lidarr.git
synced 2025-07-15 09:33:52 -07:00
New: Add Download Client validation for indexers
(cherry picked from commit e53b7f8c945e3597ca1719961e82540f1f01f0e9) Closes #4246
This commit is contained in:
parent
bdd9628122
commit
9ccb6af61b
2 changed files with 30 additions and 1 deletions
|
@ -1,5 +1,6 @@
|
||||||
using Lidarr.Http;
|
using Lidarr.Http;
|
||||||
using NzbDrone.Core.Indexers;
|
using NzbDrone.Core.Indexers;
|
||||||
|
using NzbDrone.Core.Validation;
|
||||||
|
|
||||||
namespace Lidarr.Api.V1.Indexers
|
namespace Lidarr.Api.V1.Indexers
|
||||||
{
|
{
|
||||||
|
@ -9,9 +10,10 @@ namespace Lidarr.Api.V1.Indexers
|
||||||
public static readonly IndexerResourceMapper ResourceMapper = new ();
|
public static readonly IndexerResourceMapper ResourceMapper = new ();
|
||||||
public static readonly IndexerBulkResourceMapper BulkResourceMapper = new ();
|
public static readonly IndexerBulkResourceMapper BulkResourceMapper = new ();
|
||||||
|
|
||||||
public IndexerController(IndexerFactory indexerFactory)
|
public IndexerController(IndexerFactory indexerFactory, DownloadClientExistsValidator downloadClientExistsValidator)
|
||||||
: base(indexerFactory, "indexer", ResourceMapper, BulkResourceMapper)
|
: base(indexerFactory, "indexer", ResourceMapper, BulkResourceMapper)
|
||||||
{
|
{
|
||||||
|
SharedValidator.RuleFor(c => c.DownloadClientId).SetValidator(downloadClientExistsValidator);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue