mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-17 21:26:22 -04:00
New: Allowed sort keys for paginated resources
This commit is contained in:
@@ -38,7 +38,11 @@ namespace Radarr.Http
|
||||
|
||||
public static class PagingResourceMapper
|
||||
{
|
||||
public static PagingSpec<TModel> MapToPagingSpec<TResource, TModel>(this PagingResource<TResource> pagingResource, string defaultSortKey = "Id", SortDirection defaultSortDirection = SortDirection.Ascending)
|
||||
public static PagingSpec<TModel> MapToPagingSpec<TResource, TModel>(
|
||||
this PagingResource<TResource> pagingResource,
|
||||
string defaultSortKey = "Id",
|
||||
SortDirection defaultSortDirection = SortDirection.Ascending,
|
||||
HashSet<string> allowedSortKeys = null)
|
||||
{
|
||||
var pagingSpec = new PagingSpec<TModel>
|
||||
{
|
||||
@@ -57,6 +61,13 @@ namespace Radarr.Http
|
||||
}
|
||||
}
|
||||
|
||||
if (pagingResource.SortKey != null &&
|
||||
allowedSortKeys is { Count: > 0 } &&
|
||||
!allowedSortKeys.Contains(pagingResource.SortKey))
|
||||
{
|
||||
pagingSpec.SortKey = defaultSortKey;
|
||||
}
|
||||
|
||||
return pagingSpec;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user