Lidarr/src/Lidarr.Http/PagingResource.cs

42 lines
1.4 KiB
C#
Raw Normal View History

2017-09-04 02:20:56 +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
2017-09-04 02:20:56 +00:00
namespace Lidarr.Http
2013-05-02 05:50:34 +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; }
2018-03-15 01:28:46 +00:00
public List<PagingResourceFilter> Filters { get; set; }
2013-05-02 05:50:34 +00:00
public int TotalRecords { get; set; }
public List<TResource> Records { get; set; }
}
public static class PagingResourceMapper
{
public static PagingSpec<TModel> MapToPagingSpec<TResource, TModel>(this PagingResource<TResource> pagingResource, string defaultSortKey = "Id", SortDirection defaultSortDirection = SortDirection.Ascending)
{
var pagingSpec = new PagingSpec<TModel>
{
Page = pagingResource.Page,
PageSize = pagingResource.PageSize,
SortKey = pagingResource.SortKey,
SortDirection = pagingResource.SortDirection,
};
if (pagingResource.SortKey == null)
{
pagingSpec.SortKey = defaultSortKey;
if(pagingResource.SortDirection == SortDirection.Default)
{
pagingSpec.SortDirection = defaultSortDirection;
}
}
return pagingSpec;
}
2013-05-02 05:50:34 +00:00
}
}