From 7d131fbb3da0288387a48f62297eb366b3f51c2d Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Fri, 5 Apr 2019 20:23:59 -0700 Subject: [PATCH] ReleasePushModule uses ReadResourceFromRequest --- .../Indexers/ReleasePushModule.cs | 21 +++++-------------- .../Indexers/ReleasePushModule.cs | 21 +++++-------------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/NzbDrone.Api/Indexers/ReleasePushModule.cs b/src/NzbDrone.Api/Indexers/ReleasePushModule.cs index 61e5a760a..8afcf3b61 100644 --- a/src/NzbDrone.Api/Indexers/ReleasePushModule.cs +++ b/src/NzbDrone.Api/Indexers/ReleasePushModule.cs @@ -2,7 +2,6 @@ using System.Linq; using FluentValidation; using Nancy; -using Nancy.ModelBinding; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Core.Datastore; @@ -11,7 +10,6 @@ using NzbDrone.Core.Download; using NzbDrone.Core.Indexers; using NzbDrone.Core.Parser.Model; using Sonarr.Http.Extensions; -using Sonarr.Http.REST; namespace NzbDrone.Api.Indexers { @@ -20,7 +18,6 @@ namespace NzbDrone.Api.Indexers private readonly IMakeDownloadDecision _downloadDecisionMaker; private readonly IProcessDownloadDecisions _downloadDecisionProcessor; private readonly IIndexerFactory _indexerFactory; - private ResourceValidator _releaseValidator; private readonly Logger _logger; public ReleasePushModule(IMakeDownloadDecision downloadDecisionMaker, @@ -33,24 +30,16 @@ namespace NzbDrone.Api.Indexers _indexerFactory = indexerFactory; _logger = logger; - Post["/push"] = x => ProcessRelease(this.Bind()); + Post["/push"] = x => ProcessRelease(ReadResourceFromRequest()); - _releaseValidator = new ResourceValidator(); - _releaseValidator.RuleFor(s => s.Title).NotEmpty(); - _releaseValidator.RuleFor(s => s.DownloadUrl).NotEmpty(); - _releaseValidator.RuleFor(s => s.DownloadProtocol).NotEmpty(); - _releaseValidator.RuleFor(s => s.PublishDate).NotEmpty(); + PostValidator.RuleFor(s => s.Title).NotEmpty(); + PostValidator.RuleFor(s => s.DownloadUrl).NotEmpty(); + PostValidator.RuleFor(s => s.DownloadProtocol).NotEmpty(); + PostValidator.RuleFor(s => s.PublishDate).NotEmpty(); } private Response ProcessRelease(ReleaseResource release) { - var validationFailures = _releaseValidator.Validate(release).Errors; - - if (validationFailures.Any()) - { - throw new ValidationException(validationFailures); - } - _logger.Info("Release pushed: {0} - {1}", release.Title, release.DownloadUrl); var info = release.ToModel(); diff --git a/src/Sonarr.Api.V3/Indexers/ReleasePushModule.cs b/src/Sonarr.Api.V3/Indexers/ReleasePushModule.cs index beef2f2d8..912831053 100644 --- a/src/Sonarr.Api.V3/Indexers/ReleasePushModule.cs +++ b/src/Sonarr.Api.V3/Indexers/ReleasePushModule.cs @@ -3,7 +3,6 @@ using System.Linq; using FluentValidation; using FluentValidation.Results; using Nancy; -using Nancy.ModelBinding; using NLog; using NzbDrone.Common.Extensions; using NzbDrone.Core.Datastore; @@ -12,7 +11,6 @@ using NzbDrone.Core.Download; using NzbDrone.Core.Indexers; using NzbDrone.Core.Parser.Model; using Sonarr.Http.Extensions; -using Sonarr.Http.REST; namespace Sonarr.Api.V3.Indexers { @@ -21,7 +19,6 @@ namespace Sonarr.Api.V3.Indexers private readonly IMakeDownloadDecision _downloadDecisionMaker; private readonly IProcessDownloadDecisions _downloadDecisionProcessor; private readonly IIndexerFactory _indexerFactory; - private ResourceValidator _releaseValidator; private readonly Logger _logger; public ReleasePushModule(IMakeDownloadDecision downloadDecisionMaker, @@ -34,24 +31,16 @@ namespace Sonarr.Api.V3.Indexers _indexerFactory = indexerFactory; _logger = logger; - _releaseValidator = new ResourceValidator(); - _releaseValidator.RuleFor(s => s.Title).NotEmpty(); - _releaseValidator.RuleFor(s => s.DownloadUrl).NotEmpty(); - _releaseValidator.RuleFor(s => s.DownloadProtocol).NotEmpty(); - _releaseValidator.RuleFor(s => s.PublishDate).NotEmpty(); + PostValidator.RuleFor(s => s.Title).NotEmpty(); + PostValidator.RuleFor(s => s.DownloadUrl).NotEmpty(); + PostValidator.RuleFor(s => s.DownloadProtocol).NotEmpty(); + PostValidator.RuleFor(s => s.PublishDate).NotEmpty(); - Post["/push"] = x => ProcessRelease(this.Bind()); + Post["/push"] = x => ProcessRelease(ReadResourceFromRequest()); } private Response ProcessRelease(ReleaseResource release) { - var validationFailures = _releaseValidator.Validate(release).Errors; - - if (validationFailures.Any()) - { - throw new ValidationException(validationFailures); - } - _logger.Info("Release pushed: {0} - {1}", release.Title, release.DownloadUrl); var info = release.ToModel();