moving validation rules to restmodule.

pull/23/head
kay.one 12 years ago
parent cc11e3760a
commit 373a93be64

@ -3,7 +3,7 @@ using NzbDrone.Api.REST;
namespace NzbDrone.Api.QualityType
{
public class QualitySizeResource : RestResource<QualitySizeResource>
public class QualitySizeResource : RestResource
{
public String Name { get; set; }
public Int32 MinSize { get; set; }

@ -6,7 +6,7 @@ using NzbDrone.Api.Extensions;
namespace NzbDrone.Api.REST
{
public abstract class RestModule<TResource> : NancyModule
where TResource : RestResource<TResource>, 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<int> 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;

@ -2,10 +2,8 @@
namespace NzbDrone.Api.REST
{
public abstract class RestResource<T>
where T : RestResource<T>, 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<T> PostValidator { get; private set; }
protected AbstractValidator<T> PutValidator { get; private set; }
public RestResource()
{
PostValidator = new InlineValidator<T>();
PutValidator = new InlineValidator<T>();
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);
}
}
}

@ -4,7 +4,7 @@ using NzbDrone.Api.REST;
namespace NzbDrone.Api.Series
{
public class SeriesResource : RestResource<SeriesResource>
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?

@ -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
{

Loading…
Cancel
Save