1
0
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:
Bogdan
2024-09-16 19:49:23 +03:00
parent 3ca327f611
commit fabd40cbae
8 changed files with 73 additions and 20 deletions

View File

@@ -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;
}
}