You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.3 KiB
40 lines
1.3 KiB
using System;
|
|
using NzbDrone.Api.REST;
|
|
using NzbDrone.Api.Validation;
|
|
using NzbDrone.Core.Datastore;
|
|
|
|
namespace NzbDrone.Api
|
|
{
|
|
public abstract class NzbDroneRestModule<TResource> : RestModule<TResource> where TResource : RestResource, new()
|
|
{
|
|
protected string Resource { get; private set; }
|
|
|
|
protected NzbDroneRestModule()
|
|
: this(new TResource().ResourceName)
|
|
{
|
|
}
|
|
|
|
protected NzbDroneRestModule(string resource)
|
|
: base("/api/" + resource.Trim('/'))
|
|
{
|
|
Resource = resource;
|
|
PostValidator.RuleFor(r => r.Id).IsZero();
|
|
PutValidator.RuleFor(r => r.Id).ValidId();
|
|
}
|
|
|
|
protected PagingResource<TResource> ApplyToPage<TModel>(Func<PagingSpec<TModel>, PagingSpec<TModel>> function, PagingSpec<TModel> pagingSpec, Converter<TModel, TResource> mapper)
|
|
{
|
|
pagingSpec = function(pagingSpec);
|
|
|
|
return new PagingResource<TResource>
|
|
{
|
|
Page = pagingSpec.Page,
|
|
PageSize = pagingSpec.PageSize,
|
|
SortDirection = pagingSpec.SortDirection,
|
|
SortKey = pagingSpec.SortKey,
|
|
TotalRecords = pagingSpec.TotalRecords,
|
|
Records = pagingSpec.Records.ConvertAll(mapper)
|
|
};
|
|
}
|
|
}
|
|
} |