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.
43 lines
1.4 KiB
43 lines
1.4 KiB
7 years ago
|
using System.Collections.Generic;
|
||
12 years ago
|
using NzbDrone.Core.Datastore;
|
||
12 years ago
|
|
||
7 years ago
|
namespace Lidarr.Http
|
||
12 years ago
|
{
|
||
9 years ago
|
public class PagingResource<TResource>
|
||
12 years ago
|
{
|
||
|
public int Page { get; set; }
|
||
12 years ago
|
public int PageSize { get; set; }
|
||
12 years ago
|
public string SortKey { get; set; }
|
||
12 years ago
|
public SortDirection SortDirection { get; set; }
|
||
11 years ago
|
public string FilterKey { get; set; }
|
||
|
public string FilterValue { get; set; }
|
||
12 years ago
|
public int TotalRecords { get; set; }
|
||
9 years ago
|
public List<TResource> Records { get; set; }
|
||
|
}
|
||
|
|
||
|
public static class PagingResourceMapper
|
||
|
{
|
||
8 years ago
|
public static PagingSpec<TModel> MapToPagingSpec<TResource, TModel>(this PagingResource<TResource> pagingResource, string defaultSortKey = "Id", SortDirection defaultSortDirection = SortDirection.Ascending)
|
||
9 years ago
|
{
|
||
8 years ago
|
var pagingSpec = new PagingSpec<TModel>
|
||
9 years ago
|
{
|
||
8 years ago
|
Page = pagingResource.Page,
|
||
|
PageSize = pagingResource.PageSize,
|
||
|
SortKey = pagingResource.SortKey,
|
||
|
SortDirection = pagingResource.SortDirection,
|
||
9 years ago
|
};
|
||
8 years ago
|
|
||
|
if (pagingResource.SortKey == null)
|
||
|
{
|
||
|
pagingSpec.SortKey = defaultSortKey;
|
||
|
if(pagingResource.SortDirection == SortDirection.Default)
|
||
|
{
|
||
|
pagingSpec.SortDirection = defaultSortDirection;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return pagingSpec;
|
||
9 years ago
|
}
|
||
12 years ago
|
}
|
||
|
}
|