1
0
mirror of https://github.com/Radarr/Radarr.git synced 2026-04-16 21:15:33 -04:00

Simplify fallback to default for allowed sort keys

Co-authored-by: Mark McDowall <mark@mcdowall.ca>
This commit is contained in:
Bogdan
2024-09-21 01:35:47 +03:00
parent b89271fc01
commit dbc94dbe4e
8 changed files with 34 additions and 34 deletions

View File

@@ -40,9 +40,9 @@ namespace Radarr.Http
{
public static PagingSpec<TModel> MapToPagingSpec<TResource, TModel>(
this PagingResource<TResource> pagingResource,
string defaultSortKey = "Id",
SortDirection defaultSortDirection = SortDirection.Ascending,
HashSet<string> allowedSortKeys = null)
HashSet<string> allowedSortKeys,
string defaultSortKey = "id",
SortDirection defaultSortDirection = SortDirection.Ascending)
{
var pagingSpec = new PagingSpec<TModel>
{
@@ -52,21 +52,15 @@ namespace Radarr.Http
SortDirection = pagingResource.SortDirection,
};
if (pagingResource.SortKey == null)
{
pagingSpec.SortKey = defaultSortKey;
if (pagingResource.SortDirection == SortDirection.Default)
{
pagingSpec.SortDirection = defaultSortDirection;
}
}
pagingSpec.SortKey = pagingResource.SortKey != null &&
allowedSortKeys is { Count: > 0 } &&
allowedSortKeys.Contains(pagingResource.SortKey)
? pagingResource.SortKey
: defaultSortKey;
if (pagingResource.SortKey != null &&
allowedSortKeys is { Count: > 0 } &&
!allowedSortKeys.Contains(pagingResource.SortKey))
{
pagingSpec.SortKey = defaultSortKey;
}
pagingSpec.SortDirection = pagingResource.SortDirection == SortDirection.Default
? defaultSortDirection
: pagingResource.SortDirection;
return pagingSpec;
}