From 373a93be648e046708ec0b37e33d90375ff41654 Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Sat, 20 Apr 2013 13:16:33 -0700 Subject: [PATCH] moving validation rules to restmodule. --- .../QualityType/QualitySizeResource.cs | 2 +- NzbDrone.Api/REST/RestModule.cs | 10 ++++--- NzbDrone.Api/REST/RestResource.cs | 27 +------------------ NzbDrone.Api/Series/SeriesResource.cs | 2 +- NzbDrone.Core/Configuration/ConfigService.cs | 2 -- 5 files changed, 10 insertions(+), 33 deletions(-) diff --git a/NzbDrone.Api/QualityType/QualitySizeResource.cs b/NzbDrone.Api/QualityType/QualitySizeResource.cs index f1dd33c5b..1cc12efb6 100644 --- a/NzbDrone.Api/QualityType/QualitySizeResource.cs +++ b/NzbDrone.Api/QualityType/QualitySizeResource.cs @@ -3,7 +3,7 @@ using NzbDrone.Api.REST; namespace NzbDrone.Api.QualityType { - public class QualitySizeResource : RestResource + public class QualitySizeResource : RestResource { public String Name { get; set; } public Int32 MinSize { get; set; } diff --git a/NzbDrone.Api/REST/RestModule.cs b/NzbDrone.Api/REST/RestModule.cs index a1b4f0ee0..6e5d9f7d5 100644 --- a/NzbDrone.Api/REST/RestModule.cs +++ b/NzbDrone.Api/REST/RestModule.cs @@ -6,7 +6,7 @@ using NzbDrone.Api.Extensions; namespace NzbDrone.Api.REST { public abstract class RestModule : NancyModule - where TResource : RestResource, new() + where TResource : RestResource, new() { private const string ROOT_ROUTE = "/"; private const string ID_ROUTE = "/{id}"; @@ -54,6 +54,10 @@ namespace NzbDrone.Api.REST DeleteResource(options.Id); return new Response { StatusCode = HttpStatusCode.OK }; }; + + + + } protected Action DeleteResource { get; set; } @@ -76,11 +80,11 @@ namespace NzbDrone.Api.REST if (Request.Method.Equals("POST", StringComparison.InvariantCultureIgnoreCase)) { - resource.ValidateForPost(); + //resource.ValidateForPost(); } else if (Request.Method.Equals("PUT", StringComparison.InvariantCultureIgnoreCase)) { - resource.ValidateForPut(); + //resource.ValidateForPut(); } return resource; diff --git a/NzbDrone.Api/REST/RestResource.cs b/NzbDrone.Api/REST/RestResource.cs index 5c93cea88..03f547a5a 100644 --- a/NzbDrone.Api/REST/RestResource.cs +++ b/NzbDrone.Api/REST/RestResource.cs @@ -2,10 +2,8 @@ namespace NzbDrone.Api.REST { - public abstract class RestResource - where T : RestResource, new() + public abstract class RestResource { - public int Id { get; set; } public virtual string ResourceName @@ -15,28 +13,5 @@ namespace NzbDrone.Api.REST return GetType().Name.ToLower(); } } - - protected AbstractValidator PostValidator { get; private set; } - protected AbstractValidator PutValidator { get; private set; } - - public RestResource() - { - PostValidator = new InlineValidator(); - PutValidator = new InlineValidator(); - - PostValidator.RuleFor(m => m.Id).Equal(0); - PutValidator.RuleFor(m => m.Id).GreaterThan(0); - } - - - public void ValidateForPost() - { - PostValidator.ValidateAndThrow((T)this); - } - - public void ValidateForPut() - { - PutValidator.ValidateAndThrow((T)this); - } } } \ No newline at end of file diff --git a/NzbDrone.Api/Series/SeriesResource.cs b/NzbDrone.Api/Series/SeriesResource.cs index 158d12f40..4583db6e6 100644 --- a/NzbDrone.Api/Series/SeriesResource.cs +++ b/NzbDrone.Api/Series/SeriesResource.cs @@ -4,7 +4,7 @@ using NzbDrone.Api.REST; namespace NzbDrone.Api.Series { - public class SeriesResource : RestResource + public class SeriesResource : RestResource { //Todo: Sorters should be done completely on the client //Todo: Is there an easy way to keep IgnoreArticlesWhenSorting in sync between, Series, History, Missing? diff --git a/NzbDrone.Core/Configuration/ConfigService.cs b/NzbDrone.Core/Configuration/ConfigService.cs index 927c2cebe..f874c90d3 100644 --- a/NzbDrone.Core/Configuration/ConfigService.cs +++ b/NzbDrone.Core/Configuration/ConfigService.cs @@ -3,10 +3,8 @@ using System.Collections.Generic; using System.Linq; using NLog; using NzbDrone.Core.Download; -using NzbDrone.Core.Model; using NzbDrone.Core.Download.Clients.Nzbget; using NzbDrone.Core.Download.Clients.Sabnzbd; -using NzbDrone.Core.Providers; namespace NzbDrone.Core.Configuration {