mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 21:43:33 -07:00
Introducing Fancy.Nx
This commit is contained in:
parent
8a52b8da02
commit
55ece3d80d
4 changed files with 135 additions and 3 deletions
42
NzbDrone.Api/REST/RestResource.cs
Normal file
42
NzbDrone.Api/REST/RestResource.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using FluentValidation;
|
||||
|
||||
namespace NzbDrone.Api.REST
|
||||
{
|
||||
public abstract class RestResource<T>
|
||||
where T : RestResource<T>, new()
|
||||
{
|
||||
|
||||
public int Id { get; set; }
|
||||
|
||||
public virtual string ResourceName
|
||||
{
|
||||
get
|
||||
{
|
||||
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