mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-14 10:47:08 -07:00
moving validation rules to restmodule.
This commit is contained in:
parent
cc11e3760a
commit
373a93be64
5 changed files with 10 additions and 33 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue