mirror of
https://github.com/fergalmoran/Readarr.git
synced 2026-01-30 04:24:02 +00:00
Fix some Build Issues, Renaming
This commit is contained in:
56
src/Lidarr.Http/LidarrRestModule.cs
Normal file
56
src/Lidarr.Http/LidarrRestModule.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using NzbDrone.Core.Datastore;
|
||||
using Lidarr.Http.REST;
|
||||
using Lidarr.Http.Validation;
|
||||
|
||||
namespace Lidarr.Http
|
||||
{
|
||||
public abstract class LidarrRestModule<TResource> : RestModule<TResource> where TResource : RestResource, new()
|
||||
{
|
||||
protected string Resource { get; private set; }
|
||||
|
||||
|
||||
private static string BaseUrl()
|
||||
{
|
||||
var isV3 = typeof(TResource).Namespace.Contains(".V3.");
|
||||
if (isV3)
|
||||
{
|
||||
return "/api/v3/";
|
||||
}
|
||||
return "/api/";
|
||||
}
|
||||
|
||||
private static string ResourceName()
|
||||
{
|
||||
return new TResource().ResourceName.Trim('/').ToLower();
|
||||
}
|
||||
|
||||
protected LidarrRestModule()
|
||||
: this(ResourceName())
|
||||
{
|
||||
}
|
||||
|
||||
protected LidarrRestModule(string resource)
|
||||
: base(BaseUrl() + resource.Trim('/').ToLower())
|
||||
{
|
||||
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)
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user