2013-07-19 03:47:55 +00:00
|
|
|
|
using System.Collections.Generic;
|
2013-05-13 06:12:19 +00:00
|
|
|
|
using NzbDrone.Core.Datastore;
|
2013-05-02 05:50:34 +00:00
|
|
|
|
|
|
|
|
|
namespace NzbDrone.Api
|
|
|
|
|
{
|
2016-03-25 00:56:29 +00:00
|
|
|
|
public class PagingResource<TResource>
|
2013-05-02 05:50:34 +00:00
|
|
|
|
{
|
|
|
|
|
public int Page { get; set; }
|
2013-05-13 06:12:19 +00:00
|
|
|
|
public int PageSize { get; set; }
|
2013-05-02 05:50:34 +00:00
|
|
|
|
public string SortKey { get; set; }
|
2013-05-13 06:12:19 +00:00
|
|
|
|
public SortDirection SortDirection { get; set; }
|
2014-02-01 22:09:22 +00:00
|
|
|
|
public string FilterKey { get; set; }
|
|
|
|
|
public string FilterValue { get; set; }
|
2013-05-02 05:50:34 +00:00
|
|
|
|
public int TotalRecords { get; set; }
|
2016-03-25 00:56:29 +00:00
|
|
|
|
public List<TResource> Records { get; set; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class PagingResourceMapper
|
|
|
|
|
{
|
2016-09-10 21:05:34 +00:00
|
|
|
|
public static PagingSpec<TModel> MapToPagingSpec<TResource, TModel>(this PagingResource<TResource> pagingResource, string defaultSortKey = "Id", SortDirection defaultSortDirection = SortDirection.Ascending)
|
2016-03-25 00:56:29 +00:00
|
|
|
|
{
|
2016-09-10 21:05:34 +00:00
|
|
|
|
var pagingSpec = new PagingSpec<TModel>
|
2016-03-25 00:56:29 +00:00
|
|
|
|
{
|
2016-09-10 21:05:34 +00:00
|
|
|
|
Page = pagingResource.Page,
|
|
|
|
|
PageSize = pagingResource.PageSize,
|
|
|
|
|
SortKey = pagingResource.SortKey,
|
|
|
|
|
SortDirection = pagingResource.SortDirection,
|
2016-03-25 00:56:29 +00:00
|
|
|
|
};
|
2016-09-10 21:05:34 +00:00
|
|
|
|
|
|
|
|
|
if (pagingResource.SortKey == null)
|
|
|
|
|
{
|
|
|
|
|
pagingSpec.SortKey = defaultSortKey;
|
|
|
|
|
if(pagingResource.SortDirection == SortDirection.Default)
|
|
|
|
|
{
|
|
|
|
|
pagingSpec.SortDirection = defaultSortDirection;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pagingSpec;
|
2016-03-25 00:56:29 +00:00
|
|
|
|
}
|
2013-05-02 05:50:34 +00:00
|
|
|
|
}
|
|
|
|
|
}
|