mirror of
https://github.com/Radarr/Radarr
synced 2024-12-26 17:59:14 +00:00
moving validation rules to restmodule.
This commit is contained in:
parent
cc11e3760a
commit
373a93be64
5 changed files with 10 additions and 33 deletions
|
@ -3,7 +3,7 @@
|
|||
|
||||
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 @@
|
|||
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 @@ protected RestModule(string modulePath)
|
|||
DeleteResource(options.Id);
|
||||
return new Response { StatusCode = HttpStatusCode.OK };
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected Action<int> DeleteResource { get; set; }
|
||||
|
@ -76,11 +80,11 @@ private TResource ReadFromRequest()
|
|||
|
||||
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 @@ public virtual string ResourceName
|
|||
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 @@
|
|||
|
||||
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.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…
Reference in a new issue