|
|
|
@ -1,5 +1,4 @@
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net;
|
|
|
|
|
using Microsoft.AspNetCore.Http;
|
|
|
|
@ -27,69 +26,6 @@ namespace Prowlarr.Http.Extensions
|
|
|
|
|
return defaultValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static PagingResource<TResource> ReadPagingResourceFromRequest<TResource>(this HttpRequest request)
|
|
|
|
|
{
|
|
|
|
|
if (!int.TryParse(request.Query["PageSize"].ToString(), out var pageSize))
|
|
|
|
|
{
|
|
|
|
|
pageSize = 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!int.TryParse(request.Query["Page"].ToString(), out var page))
|
|
|
|
|
{
|
|
|
|
|
page = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var pagingResource = new PagingResource<TResource>
|
|
|
|
|
{
|
|
|
|
|
PageSize = pageSize,
|
|
|
|
|
Page = page,
|
|
|
|
|
Filters = new List<PagingResourceFilter>()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (request.Query["SortKey"].Any())
|
|
|
|
|
{
|
|
|
|
|
var sortKey = request.Query["SortKey"].ToString();
|
|
|
|
|
|
|
|
|
|
pagingResource.SortKey = sortKey;
|
|
|
|
|
|
|
|
|
|
if (request.Query["SortDirection"].Any())
|
|
|
|
|
{
|
|
|
|
|
pagingResource.SortDirection = request.Query["SortDirection"].ToString()
|
|
|
|
|
.Equals("ascending", StringComparison.InvariantCultureIgnoreCase)
|
|
|
|
|
? SortDirection.Ascending
|
|
|
|
|
: SortDirection.Descending;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// For backwards compatibility with v2
|
|
|
|
|
if (request.Query["FilterKey"].Any())
|
|
|
|
|
{
|
|
|
|
|
var filter = new PagingResourceFilter
|
|
|
|
|
{
|
|
|
|
|
Key = request.Query["FilterKey"].ToString()
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (request.Query["FilterValue"].Any())
|
|
|
|
|
{
|
|
|
|
|
filter.Value = request.Query["FilterValue"].ToString();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pagingResource.Filters.Add(filter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// v3 uses filters in key=value format
|
|
|
|
|
foreach (var pair in request.Query)
|
|
|
|
|
{
|
|
|
|
|
pagingResource.Filters.Add(new PagingResourceFilter
|
|
|
|
|
{
|
|
|
|
|
Key = pair.Key,
|
|
|
|
|
Value = pair.Value.ToString()
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return pagingResource;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static PagingResource<TResource> ApplyToPage<TResource, TModel>(this PagingSpec<TModel> pagingSpec, Func<PagingSpec<TModel>, PagingSpec<TModel>> function, Converter<TModel, TResource> mapper)
|
|
|
|
|
{
|
|
|
|
|
pagingSpec = function(pagingSpec);
|
|
|
|
|