From 73fb40de04ec219d6045e98181448515ca497801 Mon Sep 17 00:00:00 2001 From: Robert Dailey Date: Fri, 2 Sep 2022 16:51:13 -0500 Subject: [PATCH] refactor: Move CF config objects to ServiceConfiguration --- .../Services/ConfigurationLoaderTest.cs | 2 ++ .../Processors/GuideProcessorTest.cs | 2 +- .../Processors/GuideSteps/ConfigStepTest.cs | 2 +- .../GuideSteps/CustomFormatStepTest.cs | 2 +- .../GuideSteps/QualityProfileStepTest.cs | 2 +- .../Radarr/RadarrConfigurationTest.cs | 1 + .../Sonarr/SonarrCompatibilityTest.cs | 2 +- .../Config/Services/IServiceConfiguration.cs | 2 ++ .../Config/Services/ServiceConfiguration.cs | 20 +++++++++++++++++++ .../CustomFormat/CustomFormatUpdater.cs | 1 - .../CustomFormat/ICustomFormatUpdater.cs | 2 +- .../Models/ProcessedConfigData.cs | 2 +- .../CustomFormat/Processors/GuideProcessor.cs | 2 +- .../Processors/GuideSteps/ConfigStep.cs | 2 +- .../Processors/GuideSteps/CustomFormatStep.cs | 2 +- .../Processors/GuideSteps/IConfigStep.cs | 2 +- .../GuideSteps/ICustomFormatStep.cs | 2 +- .../Processors/IGuideProcessor.cs | 2 +- .../Processors/PersistenceProcessor.cs | 3 +-- .../Radarr/Config/RadarrConfiguration.cs | 18 ----------------- .../Config/RadarrConfigurationValidator.cs | 1 + .../Sonarr/Config/SonarrConfiguration.cs | 2 -- 22 files changed, 40 insertions(+), 36 deletions(-) diff --git a/src/Recyclarr.Tests/Config/Services/ConfigurationLoaderTest.cs b/src/Recyclarr.Tests/Config/Services/ConfigurationLoaderTest.cs index 7ad36265..9b9d00e4 100644 --- a/src/Recyclarr.Tests/Config/Services/ConfigurationLoaderTest.cs +++ b/src/Recyclarr.Tests/Config/Services/ConfigurationLoaderTest.cs @@ -50,6 +50,8 @@ public class ConfigurationLoaderTest { public string BaseUrl => ""; public string ApiKey => ""; + public ICollection CustomFormats => new List(); + public bool DeleteOldCustomFormats => false; } [Test, AutoMockData(typeof(ConfigurationLoaderTest), nameof(BuildContainer))] diff --git a/src/TrashLib.Tests/CustomFormat/Processors/GuideProcessorTest.cs b/src/TrashLib.Tests/CustomFormat/Processors/GuideProcessorTest.cs index f9323701..4d541e93 100644 --- a/src/TrashLib.Tests/CustomFormat/Processors/GuideProcessorTest.cs +++ b/src/TrashLib.Tests/CustomFormat/Processors/GuideProcessorTest.cs @@ -6,12 +6,12 @@ using NSubstitute; using NUnit.Framework; using Serilog; using TestLibrary.FluentAssertions; +using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Guide; using TrashLib.Services.CustomFormat.Models; using TrashLib.Services.CustomFormat.Processors; using TrashLib.Services.CustomFormat.Processors.GuideSteps; using TrashLib.Services.Radarr; -using TrashLib.Services.Radarr.Config; using TrashLib.TestLibrary; namespace TrashLib.Tests.CustomFormat.Processors; diff --git a/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/ConfigStepTest.cs b/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/ConfigStepTest.cs index e7733b21..d7a2e8c1 100644 --- a/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/ConfigStepTest.cs +++ b/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/ConfigStepTest.cs @@ -2,10 +2,10 @@ using FluentAssertions; using Newtonsoft.Json.Linq; using NUnit.Framework; using TestLibrary.AutoFixture; +using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Models; using TrashLib.Services.CustomFormat.Models.Cache; using TrashLib.Services.CustomFormat.Processors.GuideSteps; -using TrashLib.Services.Radarr.Config; using TrashLib.TestLibrary; namespace TrashLib.Tests.CustomFormat.Processors.GuideSteps; diff --git a/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/CustomFormatStepTest.cs b/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/CustomFormatStepTest.cs index d36e8a88..ced529a9 100644 --- a/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/CustomFormatStepTest.cs +++ b/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/CustomFormatStepTest.cs @@ -4,10 +4,10 @@ using Newtonsoft.Json.Linq; using NUnit.Framework; using TestLibrary.AutoFixture; using TestLibrary.FluentAssertions; +using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Models; using TrashLib.Services.CustomFormat.Models.Cache; using TrashLib.Services.CustomFormat.Processors.GuideSteps; -using TrashLib.Services.Radarr.Config; using TrashLib.TestLibrary; namespace TrashLib.Tests.CustomFormat.Processors.GuideSteps; diff --git a/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/QualityProfileStepTest.cs b/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/QualityProfileStepTest.cs index 5af23046..f002c667 100644 --- a/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/QualityProfileStepTest.cs +++ b/src/TrashLib.Tests/CustomFormat/Processors/GuideSteps/QualityProfileStepTest.cs @@ -1,8 +1,8 @@ using FluentAssertions; using NUnit.Framework; +using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Models; using TrashLib.Services.CustomFormat.Processors.GuideSteps; -using TrashLib.Services.Radarr.Config; using TrashLib.TestLibrary; namespace TrashLib.Tests.CustomFormat.Processors.GuideSteps; diff --git a/src/TrashLib.Tests/Radarr/RadarrConfigurationTest.cs b/src/TrashLib.Tests/Radarr/RadarrConfigurationTest.cs index 61b3ce22..40f62250 100644 --- a/src/TrashLib.Tests/Radarr/RadarrConfigurationTest.cs +++ b/src/TrashLib.Tests/Radarr/RadarrConfigurationTest.cs @@ -4,6 +4,7 @@ using FluentAssertions; using FluentValidation; using NUnit.Framework; using TrashLib.Config; +using TrashLib.Config.Services; using TrashLib.Services.Radarr; using TrashLib.Services.Radarr.Config; diff --git a/src/TrashLib.Tests/Sonarr/SonarrCompatibilityTest.cs b/src/TrashLib.Tests/Sonarr/SonarrCompatibilityTest.cs index 302118db..48407028 100644 --- a/src/TrashLib.Tests/Sonarr/SonarrCompatibilityTest.cs +++ b/src/TrashLib.Tests/Sonarr/SonarrCompatibilityTest.cs @@ -8,8 +8,8 @@ using Newtonsoft.Json.Serialization; using NSubstitute; using NUnit.Framework; using TestLibrary.AutoFixture; +using TrashLib.Config.Services; using TrashLib.ExceptionTypes; -using TrashLib.Services.Radarr.Config; using TrashLib.Services.Sonarr; using TrashLib.Services.Sonarr.Api; using TrashLib.Services.Sonarr.Api.Objects; diff --git a/src/TrashLib/Config/Services/IServiceConfiguration.cs b/src/TrashLib/Config/Services/IServiceConfiguration.cs index 76dfb169..fe03bd9e 100644 --- a/src/TrashLib/Config/Services/IServiceConfiguration.cs +++ b/src/TrashLib/Config/Services/IServiceConfiguration.cs @@ -4,4 +4,6 @@ public interface IServiceConfiguration { string BaseUrl { get; } string ApiKey { get; } + ICollection CustomFormats { get; } + bool DeleteOldCustomFormats { get; } } diff --git a/src/TrashLib/Config/Services/ServiceConfiguration.cs b/src/TrashLib/Config/Services/ServiceConfiguration.cs index 47757eab..e6371943 100644 --- a/src/TrashLib/Config/Services/ServiceConfiguration.cs +++ b/src/TrashLib/Config/Services/ServiceConfiguration.cs @@ -1,7 +1,27 @@ +using JetBrains.Annotations; + namespace TrashLib.Config.Services; public abstract class ServiceConfiguration : IServiceConfiguration { public string BaseUrl { get; init; } = ""; public string ApiKey { get; init; } = ""; + public ICollection CustomFormats { get; init; } = new List(); + public bool DeleteOldCustomFormats { get; init; } +} + +[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] +public class CustomFormatConfig +{ + public ICollection Names { get; init; } = new List(); + public ICollection TrashIds { get; init; } = new List(); + public ICollection QualityProfiles { get; init; } = new List(); +} + +[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] +public class QualityProfileConfig +{ + public string Name { get; init; } = ""; + public int? Score { get; init; } + public bool ResetUnmatchedScores { get; init; } } diff --git a/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs b/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs index 7084e542..caea5ebc 100644 --- a/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs +++ b/src/TrashLib/Services/CustomFormat/CustomFormatUpdater.cs @@ -4,7 +4,6 @@ using Serilog; using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Processors; using TrashLib.Services.CustomFormat.Processors.PersistenceSteps; -using TrashLib.Services.Radarr.Config; namespace TrashLib.Services.CustomFormat; diff --git a/src/TrashLib/Services/CustomFormat/ICustomFormatUpdater.cs b/src/TrashLib/Services/CustomFormat/ICustomFormatUpdater.cs index d5b716d6..c5f22289 100644 --- a/src/TrashLib/Services/CustomFormat/ICustomFormatUpdater.cs +++ b/src/TrashLib/Services/CustomFormat/ICustomFormatUpdater.cs @@ -1,4 +1,4 @@ -using TrashLib.Services.Radarr.Config; +using TrashLib.Config.Services; namespace TrashLib.Services.CustomFormat; diff --git a/src/TrashLib/Services/CustomFormat/Models/ProcessedConfigData.cs b/src/TrashLib/Services/CustomFormat/Models/ProcessedConfigData.cs index 41cba50b..5c8ef965 100644 --- a/src/TrashLib/Services/CustomFormat/Models/ProcessedConfigData.cs +++ b/src/TrashLib/Services/CustomFormat/Models/ProcessedConfigData.cs @@ -1,4 +1,4 @@ -using TrashLib.Services.Radarr.Config; +using TrashLib.Config.Services; namespace TrashLib.Services.CustomFormat.Models; diff --git a/src/TrashLib/Services/CustomFormat/Processors/GuideProcessor.cs b/src/TrashLib/Services/CustomFormat/Processors/GuideProcessor.cs index 845e28ac..a6de168d 100644 --- a/src/TrashLib/Services/CustomFormat/Processors/GuideProcessor.cs +++ b/src/TrashLib/Services/CustomFormat/Processors/GuideProcessor.cs @@ -1,8 +1,8 @@ +using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Models; using TrashLib.Services.CustomFormat.Models.Cache; using TrashLib.Services.CustomFormat.Processors.GuideSteps; using TrashLib.Services.Radarr; -using TrashLib.Services.Radarr.Config; namespace TrashLib.Services.CustomFormat.Processors; diff --git a/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/ConfigStep.cs b/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/ConfigStep.cs index fd8598f3..d87e7777 100644 --- a/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/ConfigStep.cs +++ b/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/ConfigStep.cs @@ -1,7 +1,7 @@ using Common.Extensions; using Serilog; +using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Models; -using TrashLib.Services.Radarr.Config; namespace TrashLib.Services.CustomFormat.Processors.GuideSteps; diff --git a/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/CustomFormatStep.cs b/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/CustomFormatStep.cs index 353177fd..8ce6ec75 100644 --- a/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/CustomFormatStep.cs +++ b/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/CustomFormatStep.cs @@ -1,7 +1,7 @@ using Common.Extensions; +using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Models; using TrashLib.Services.CustomFormat.Models.Cache; -using TrashLib.Services.Radarr.Config; namespace TrashLib.Services.CustomFormat.Processors.GuideSteps; diff --git a/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/IConfigStep.cs b/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/IConfigStep.cs index 87c19c03..be454a7b 100644 --- a/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/IConfigStep.cs +++ b/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/IConfigStep.cs @@ -1,5 +1,5 @@ +using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Models; -using TrashLib.Services.Radarr.Config; namespace TrashLib.Services.CustomFormat.Processors.GuideSteps; diff --git a/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/ICustomFormatStep.cs b/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/ICustomFormatStep.cs index 912fd628..8815f523 100644 --- a/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/ICustomFormatStep.cs +++ b/src/TrashLib/Services/CustomFormat/Processors/GuideSteps/ICustomFormatStep.cs @@ -1,6 +1,6 @@ +using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Models; using TrashLib.Services.CustomFormat.Models.Cache; -using TrashLib.Services.Radarr.Config; namespace TrashLib.Services.CustomFormat.Processors.GuideSteps; diff --git a/src/TrashLib/Services/CustomFormat/Processors/IGuideProcessor.cs b/src/TrashLib/Services/CustomFormat/Processors/IGuideProcessor.cs index ad2a04c7..552072a1 100644 --- a/src/TrashLib/Services/CustomFormat/Processors/IGuideProcessor.cs +++ b/src/TrashLib/Services/CustomFormat/Processors/IGuideProcessor.cs @@ -1,6 +1,6 @@ +using TrashLib.Config.Services; using TrashLib.Services.CustomFormat.Models; using TrashLib.Services.CustomFormat.Models.Cache; -using TrashLib.Services.Radarr.Config; namespace TrashLib.Services.CustomFormat.Processors; diff --git a/src/TrashLib/Services/CustomFormat/Processors/PersistenceProcessor.cs b/src/TrashLib/Services/CustomFormat/Processors/PersistenceProcessor.cs index 97e1ba81..45782a4f 100644 --- a/src/TrashLib/Services/CustomFormat/Processors/PersistenceProcessor.cs +++ b/src/TrashLib/Services/CustomFormat/Processors/PersistenceProcessor.cs @@ -3,7 +3,6 @@ using TrashLib.Services.CustomFormat.Api; using TrashLib.Services.CustomFormat.Models; using TrashLib.Services.CustomFormat.Models.Cache; using TrashLib.Services.CustomFormat.Processors.PersistenceSteps; -using TrashLib.Services.Radarr.Config; namespace TrashLib.Services.CustomFormat.Processors; @@ -61,7 +60,7 @@ internal class PersistenceProcessor : IPersistenceProcessor _steps.JsonTransactionStep.Process(guideCfs, radarrCfs); // Step 1.1: Optionally record deletions of custom formats in cache but not in the guide - var config = (RadarrConfiguration) _configProvider.ActiveConfiguration; + var config = _configProvider.ActiveConfiguration; if (config.DeleteOldCustomFormats) { _steps.JsonTransactionStep.RecordDeletions(deletedCfsInCache, radarrCfs); diff --git a/src/TrashLib/Services/Radarr/Config/RadarrConfiguration.cs b/src/TrashLib/Services/Radarr/Config/RadarrConfiguration.cs index 1ca36a93..8e996dd8 100644 --- a/src/TrashLib/Services/Radarr/Config/RadarrConfiguration.cs +++ b/src/TrashLib/Services/Radarr/Config/RadarrConfiguration.cs @@ -7,24 +7,6 @@ namespace TrashLib.Services.Radarr.Config; public class RadarrConfiguration : ServiceConfiguration { public QualityDefinitionConfig? QualityDefinition { get; init; } - public ICollection CustomFormats { get; init; } = new List(); - public bool DeleteOldCustomFormats { get; init; } -} - -[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] -public class CustomFormatConfig -{ - public ICollection Names { get; init; } = new List(); - public ICollection TrashIds { get; init; } = new List(); - public ICollection QualityProfiles { get; init; } = new List(); -} - -[UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] -public class QualityProfileConfig -{ - public string Name { get; init; } = ""; - public int? Score { get; init; } - public bool ResetUnmatchedScores { get; init; } } [UsedImplicitly(ImplicitUseTargetFlags.WithMembers)] diff --git a/src/TrashLib/Services/Radarr/Config/RadarrConfigurationValidator.cs b/src/TrashLib/Services/Radarr/Config/RadarrConfigurationValidator.cs index be2257cf..e901ed86 100644 --- a/src/TrashLib/Services/Radarr/Config/RadarrConfigurationValidator.cs +++ b/src/TrashLib/Services/Radarr/Config/RadarrConfigurationValidator.cs @@ -1,6 +1,7 @@ using Common.FluentValidation; using FluentValidation; using JetBrains.Annotations; +using TrashLib.Config.Services; namespace TrashLib.Services.Radarr.Config; diff --git a/src/TrashLib/Services/Sonarr/Config/SonarrConfiguration.cs b/src/TrashLib/Services/Sonarr/Config/SonarrConfiguration.cs index c5cbba11..4d0d4349 100644 --- a/src/TrashLib/Services/Sonarr/Config/SonarrConfiguration.cs +++ b/src/TrashLib/Services/Sonarr/Config/SonarrConfiguration.cs @@ -1,12 +1,10 @@ using TrashLib.Config.Services; -using TrashLib.Services.Radarr.Config; namespace TrashLib.Services.Sonarr.Config; public class SonarrConfiguration : ServiceConfiguration { public IList ReleaseProfiles { get; init; } = Array.Empty(); - public ICollection CustomFormats { get; init; } = new List(); public string QualityDefinition { get; init; } = ""; }