diff --git a/src/Sonarr.Api.V5/Indexers/IndexerBulkResource.cs b/src/Sonarr.Api.V5/Indexers/IndexerBulkResource.cs new file mode 100644 index 000000000..236387d66 --- /dev/null +++ b/src/Sonarr.Api.V5/Indexers/IndexerBulkResource.cs @@ -0,0 +1,30 @@ +using NzbDrone.Core.Indexers; +using Sonarr.Api.V5.Provider; + +namespace Sonarr.Api.V5.Indexers; + +public class IndexerBulkResource : ProviderBulkResource +{ + public bool? EnableRss { get; set; } + public bool? EnableAutomaticSearch { get; set; } + public bool? EnableInteractiveSearch { get; set; } + public int? Priority { get; set; } + public int? SeasonSearchMaximumSingleEpisodeAge { get; set; } +} + +public class IndexerBulkResourceMapper : ProviderBulkResourceMapper +{ + public override List UpdateModel(IndexerBulkResource resource, List existingDefinitions) + { + existingDefinitions.ForEach(existing => + { + existing.EnableRss = resource.EnableRss ?? existing.EnableRss; + existing.EnableAutomaticSearch = resource.EnableAutomaticSearch ?? existing.EnableAutomaticSearch; + existing.EnableInteractiveSearch = resource.EnableInteractiveSearch ?? existing.EnableInteractiveSearch; + existing.Priority = resource.Priority ?? existing.Priority; + existing.SeasonSearchMaximumSingleEpisodeAge = resource.SeasonSearchMaximumSingleEpisodeAge ?? existing.SeasonSearchMaximumSingleEpisodeAge; + }); + + return existingDefinitions; + } +} diff --git a/src/Sonarr.Api.V5/Indexers/IndexerController.cs b/src/Sonarr.Api.V5/Indexers/IndexerController.cs new file mode 100644 index 000000000..82527fc54 --- /dev/null +++ b/src/Sonarr.Api.V5/Indexers/IndexerController.cs @@ -0,0 +1,25 @@ +using FluentValidation; +using NzbDrone.Core.Indexers; +using NzbDrone.Core.Validation; +using NzbDrone.SignalR; +using Sonarr.Api.V5.Provider; +using Sonarr.Http; + +namespace Sonarr.Api.V5.Indexers; + +[V5ApiController] +public class IndexerController : ProviderControllerBase +{ + public static readonly IndexerResourceMapper ResourceMapper = new(); + public static readonly IndexerBulkResourceMapper BulkResourceMapper = new(); + + public IndexerController(IBroadcastSignalRMessage signalRBroadcaster, + IndexerFactory indexerFactory, + DownloadClientExistsValidator downloadClientExistsValidator) + : base(signalRBroadcaster, indexerFactory, "indexer", ResourceMapper, BulkResourceMapper) + { + SharedValidator.RuleFor(c => c.Priority).InclusiveBetween(1, 50); + SharedValidator.RuleFor(c => c.SeasonSearchMaximumSingleEpisodeAge).GreaterThanOrEqualTo(0); + SharedValidator.RuleFor(c => c.DownloadClientId).SetValidator(downloadClientExistsValidator); + } +} diff --git a/src/Sonarr.Api.V5/Indexers/IndexerFlagController.cs b/src/Sonarr.Api.V5/Indexers/IndexerFlagController.cs new file mode 100644 index 000000000..2424b98f4 --- /dev/null +++ b/src/Sonarr.Api.V5/Indexers/IndexerFlagController.cs @@ -0,0 +1,19 @@ +using Microsoft.AspNetCore.Mvc; +using NzbDrone.Core.Parser.Model; +using Sonarr.Http; + +namespace Sonarr.Api.V5.Indexers; + +[V5ApiController] +public class IndexerFlagController : Controller +{ + [HttpGet] + public List GetAll() + { + return Enum.GetValues(typeof(IndexerFlags)).Cast().Select(f => new IndexerFlagResource + { + Id = (int)f, + Name = f.ToString() + }).ToList(); + } +} diff --git a/src/Sonarr.Api.V5/Indexers/IndexerFlagResource.cs b/src/Sonarr.Api.V5/Indexers/IndexerFlagResource.cs new file mode 100644 index 000000000..925f7be62 --- /dev/null +++ b/src/Sonarr.Api.V5/Indexers/IndexerFlagResource.cs @@ -0,0 +1,12 @@ +using Newtonsoft.Json; +using Sonarr.Http.REST; + +namespace Sonarr.Api.V5.Indexers; + +public class IndexerFlagResource : RestResource +{ + [JsonProperty(DefaultValueHandling = DefaultValueHandling.Include)] + public new int Id { get; set; } + public string? Name { get; set; } + public string? NameLower => Name?.ToLowerInvariant(); +} diff --git a/src/Sonarr.Api.V5/Indexers/IndexerResource.cs b/src/Sonarr.Api.V5/Indexers/IndexerResource.cs new file mode 100644 index 000000000..e97a69470 --- /dev/null +++ b/src/Sonarr.Api.V5/Indexers/IndexerResource.cs @@ -0,0 +1,51 @@ +using NzbDrone.Core.Indexers; +using Sonarr.Api.V5.Provider; + +namespace Sonarr.Api.V5.Indexers; + +public class IndexerResource : ProviderResource +{ + public bool EnableRss { get; set; } + public bool EnableAutomaticSearch { get; set; } + public bool EnableInteractiveSearch { get; set; } + public bool SupportsRss { get; set; } + public bool SupportsSearch { get; set; } + public DownloadProtocol Protocol { get; set; } + public int Priority { get; set; } + public int SeasonSearchMaximumSingleEpisodeAge { get; set; } + public int DownloadClientId { get; set; } +} + +public class IndexerResourceMapper : ProviderResourceMapper +{ + public override IndexerResource ToResource(IndexerDefinition definition) + { + var resource = base.ToResource(definition); + + resource.EnableRss = definition.EnableRss; + resource.EnableAutomaticSearch = definition.EnableAutomaticSearch; + resource.EnableInteractiveSearch = definition.EnableInteractiveSearch; + resource.SupportsRss = definition.SupportsRss; + resource.SupportsSearch = definition.SupportsSearch; + resource.Protocol = definition.Protocol; + resource.Priority = definition.Priority; + resource.SeasonSearchMaximumSingleEpisodeAge = definition.SeasonSearchMaximumSingleEpisodeAge; + resource.DownloadClientId = definition.DownloadClientId; + + return resource; + } + + public override IndexerDefinition ToModel(IndexerResource resource, IndexerDefinition? existingDefinition) + { + var definition = base.ToModel(resource, existingDefinition); + + definition.EnableRss = resource.EnableRss; + definition.EnableAutomaticSearch = resource.EnableAutomaticSearch; + definition.EnableInteractiveSearch = resource.EnableInteractiveSearch; + definition.Priority = resource.Priority; + definition.SeasonSearchMaximumSingleEpisodeAge = resource.SeasonSearchMaximumSingleEpisodeAge; + definition.DownloadClientId = resource.DownloadClientId; + + return definition; + } +}