Fixed: Adding indexers from presets

pull/5880/head
ta264 4 years ago committed by Qstick
parent 88b9a47c79
commit 3a146ea667

@ -2,7 +2,7 @@
namespace NzbDrone.Api.DownloadClient namespace NzbDrone.Api.DownloadClient
{ {
public class DownloadClientResource : ProviderResource public class DownloadClientResource : ProviderResource<DownloadClientResource>
{ {
public bool Enable { get; set; } public bool Enable { get; set; }
public DownloadProtocol Protocol { get; set; } public DownloadProtocol Protocol { get; set; }

@ -2,7 +2,7 @@
namespace NzbDrone.Api.Indexers namespace NzbDrone.Api.Indexers
{ {
public class IndexerResource : ProviderResource public class IndexerResource : ProviderResource<IndexerResource>
{ {
public bool EnableRss { get; set; } public bool EnableRss { get; set; }
public bool EnableSearch { get; set; } public bool EnableSearch { get; set; }

@ -1,6 +1,6 @@
namespace NzbDrone.Api.Metadata namespace NzbDrone.Api.Metadata
{ {
public class MetadataResource : ProviderResource public class MetadataResource : ProviderResource<MetadataResource>
{ {
public bool Enable { get; set; } public bool Enable { get; set; }
} }

@ -3,7 +3,7 @@ using System.Linq;
namespace NzbDrone.Api.ImportList namespace NzbDrone.Api.ImportList
{ {
public class ImportExclusionsResource : ProviderResource public class ImportExclusionsResource : ProviderResource<ImportExclusionsResource>
{ {
//public int Id { get; set; } //public int Id { get; set; }
public int TmdbId { get; set; } public int TmdbId { get; set; }

@ -3,7 +3,7 @@ using NzbDrone.Core.Movies;
namespace NzbDrone.Api.ImportList namespace NzbDrone.Api.ImportList
{ {
public class ImportListResource : ProviderResource public class ImportListResource : ProviderResource<ImportListResource>
{ {
public bool Enabled { get; set; } public bool Enabled { get; set; }
public bool EnableAuto { get; set; } public bool EnableAuto { get; set; }

@ -2,7 +2,7 @@
namespace NzbDrone.Api.Notifications namespace NzbDrone.Api.Notifications
{ {
public class NotificationResource : ProviderResource public class NotificationResource : ProviderResource<NotificationResource>
{ {
public bool OnGrab { get; set; } public bool OnGrab { get; set; }
public bool OnDownload { get; set; } public bool OnDownload { get; set; }

@ -15,7 +15,7 @@ namespace NzbDrone.Api
public abstract class ProviderModuleBase<TProviderResource, TProvider, TProviderDefinition> : RadarrRestModule<TProviderResource> public abstract class ProviderModuleBase<TProviderResource, TProvider, TProviderDefinition> : RadarrRestModule<TProviderResource>
where TProviderDefinition : ProviderDefinition, new() where TProviderDefinition : ProviderDefinition, new()
where TProvider : IProvider where TProvider : IProvider
where TProviderResource : ProviderResource, new() where TProviderResource : ProviderResource<TProviderResource>, new()
{ {
private readonly IProviderFactory<TProvider, TProviderDefinition> _providerFactory; private readonly IProviderFactory<TProvider, TProviderDefinition> _providerFactory;
@ -160,8 +160,7 @@ namespace NzbDrone.Api
{ {
var presetResource = new TProviderResource(); var presetResource = new TProviderResource();
MapToResource(presetResource, v); MapToResource(presetResource, v);
return presetResource;
return presetResource as ProviderResource;
}).ToList(); }).ToList();
result.Add(providerResource); result.Add(providerResource);

@ -5,7 +5,7 @@ using Radarr.Http.REST;
namespace NzbDrone.Api namespace NzbDrone.Api
{ {
public class ProviderResource : RestResource public class ProviderResource<T> : RestResource
{ {
public string Name { get; set; } public string Name { get; set; }
public List<Field> Fields { get; set; } public List<Field> Fields { get; set; }
@ -15,6 +15,6 @@ namespace NzbDrone.Api
public string InfoLink { get; set; } public string InfoLink { get; set; }
public ProviderMessage Message { get; set; } public ProviderMessage Message { get; set; }
public List<ProviderResource> Presets { get; set; } public List<T> Presets { get; set; }
} }
} }

@ -8,7 +8,7 @@ namespace NzbDrone.Common.Serializer
{ {
public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options) public override T Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{ {
throw new NotImplementedException(); return JsonSerializer.Deserialize<T>(ref reader, options);
} }
public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options) public override void Write(Utf8JsonWriter writer, T value, JsonSerializerOptions options)

@ -53,6 +53,14 @@ namespace NzbDrone.Integration.Test.ApiTests
return field; return field;
} }
[Test]
public void all_preset_fields_should_be_set_correctly()
{
var schema = GetNewznabSchemav3();
schema.Presets.Any(x => x.SupportsRss).Should().BeTrue();
}
[Test] [Test]
public void v2_categories_should_be_array() public void v2_categories_should_be_array()
{ {

@ -3,7 +3,7 @@ using NzbDrone.Core.Indexers;
namespace Radarr.Api.V3.DownloadClient namespace Radarr.Api.V3.DownloadClient
{ {
public class DownloadClientResource : ProviderResource public class DownloadClientResource : ProviderResource<DownloadClientResource>
{ {
public bool Enable { get; set; } public bool Enable { get; set; }
public DownloadProtocol Protocol { get; set; } public DownloadProtocol Protocol { get; set; }

@ -4,7 +4,7 @@ using NzbDrone.Core.ImportLists.ImportExclusions;
namespace Radarr.Api.V3.ImportLists namespace Radarr.Api.V3.ImportLists
{ {
public class ImportExclusionsResource : ProviderResource public class ImportExclusionsResource : ProviderResource<ImportExclusionsResource>
{ {
//public int Id { get; set; } //public int Id { get; set; }
public int TmdbId { get; set; } public int TmdbId { get; set; }

@ -3,7 +3,7 @@ using NzbDrone.Core.Movies;
namespace Radarr.Api.V3.ImportLists namespace Radarr.Api.V3.ImportLists
{ {
public class ImportListResource : ProviderResource public class ImportListResource : ProviderResource<ImportListResource>
{ {
public bool Enabled { get; set; } public bool Enabled { get; set; }
public bool EnableAuto { get; set; } public bool EnableAuto { get; set; }

@ -2,7 +2,7 @@ using NzbDrone.Core.Indexers;
namespace Radarr.Api.V3.Indexers namespace Radarr.Api.V3.Indexers
{ {
public class IndexerResource : ProviderResource public class IndexerResource : ProviderResource<IndexerResource>
{ {
public bool EnableRss { get; set; } public bool EnableRss { get; set; }
public bool EnableAutomaticSearch { get; set; } public bool EnableAutomaticSearch { get; set; }

@ -2,7 +2,7 @@ using NzbDrone.Core.Extras.Metadata;
namespace Radarr.Api.V3.Metadata namespace Radarr.Api.V3.Metadata
{ {
public class MetadataResource : ProviderResource public class MetadataResource : ProviderResource<MetadataResource>
{ {
public bool Enable { get; set; } public bool Enable { get; set; }
} }

@ -2,7 +2,7 @@ using NzbDrone.Core.Notifications;
namespace Radarr.Api.V3.Notifications namespace Radarr.Api.V3.Notifications
{ {
public class NotificationResource : ProviderResource public class NotificationResource : ProviderResource<NotificationResource>
{ {
public string Link { get; set; } public string Link { get; set; }
public bool OnGrab { get; set; } public bool OnGrab { get; set; }

@ -14,7 +14,7 @@ namespace Radarr.Api.V3
public abstract class ProviderModuleBase<TProviderResource, TProvider, TProviderDefinition> : RadarrRestModule<TProviderResource> public abstract class ProviderModuleBase<TProviderResource, TProvider, TProviderDefinition> : RadarrRestModule<TProviderResource>
where TProviderDefinition : ProviderDefinition, new() where TProviderDefinition : ProviderDefinition, new()
where TProvider : IProvider where TProvider : IProvider
where TProviderResource : ProviderResource, new() where TProviderResource : ProviderResource<TProviderResource>, new()
{ {
private readonly IProviderFactory<TProvider, TProviderDefinition> _providerFactory; private readonly IProviderFactory<TProvider, TProviderDefinition> _providerFactory;
private readonly ProviderResourceMapper<TProviderResource, TProviderDefinition> _resourceMapper; private readonly ProviderResourceMapper<TProviderResource, TProviderDefinition> _resourceMapper;
@ -124,12 +124,9 @@ namespace Radarr.Api.V3
var providerResource = _resourceMapper.ToResource(providerDefinition); var providerResource = _resourceMapper.ToResource(providerDefinition);
var presetDefinitions = _providerFactory.GetPresetDefinitions(providerDefinition); var presetDefinitions = _providerFactory.GetPresetDefinitions(providerDefinition);
providerResource.Presets = presetDefinitions.Select(v => providerResource.Presets = presetDefinitions
{ .Select(v => _resourceMapper.ToResource(v))
var presetResource = _resourceMapper.ToResource(v); .ToList();
return presetResource as ProviderResource;
}).ToList();
result.Add(providerResource); result.Add(providerResource);
} }

@ -6,7 +6,7 @@ using Radarr.Http.REST;
namespace Radarr.Api.V3 namespace Radarr.Api.V3
{ {
public class ProviderResource : RestResource public class ProviderResource<T> : RestResource
{ {
public string Name { get; set; } public string Name { get; set; }
public List<Field> Fields { get; set; } public List<Field> Fields { get; set; }
@ -17,11 +17,11 @@ namespace Radarr.Api.V3
public ProviderMessage Message { get; set; } public ProviderMessage Message { get; set; }
public HashSet<int> Tags { get; set; } public HashSet<int> Tags { get; set; }
public List<ProviderResource> Presets { get; set; } public List<T> Presets { get; set; }
} }
public class ProviderResourceMapper<TProviderResource, TProviderDefinition> public class ProviderResourceMapper<TProviderResource, TProviderDefinition>
where TProviderResource : ProviderResource, new() where TProviderResource : ProviderResource<TProviderResource>, new()
where TProviderDefinition : ProviderDefinition, new() where TProviderDefinition : ProviderDefinition, new()
{ {
public virtual TProviderResource ToResource(TProviderDefinition definition) public virtual TProviderResource ToResource(TProviderDefinition definition)

Loading…
Cancel
Save