mirror of
https://github.com/Prowlarr/Prowlarr.git
synced 2025-09-30 15:37:55 +02:00
moving validation rules to restmodule.
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user