mirror of
https://github.com/Radarr/Radarr.git
synced 2026-04-04 19:16:49 -04:00
Simplify fallback to default for allowed sort keys
Co-authored-by: Mark McDowall <mark@mcdowall.ca>
This commit is contained in:
@@ -31,8 +31,6 @@ namespace Radarr.Api.V3.Blocklist
|
||||
{
|
||||
var pagingResource = new PagingResource<BlocklistResource>(paging);
|
||||
var pagingSpec = pagingResource.MapToPagingSpec<BlocklistResource, NzbDrone.Core.Blocklisting.Blocklist>(
|
||||
"date",
|
||||
SortDirection.Descending,
|
||||
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"movieMetadata.sortTitle",
|
||||
@@ -41,7 +39,9 @@ namespace Radarr.Api.V3.Blocklist
|
||||
"quality",
|
||||
"date",
|
||||
"indexer"
|
||||
});
|
||||
},
|
||||
"date",
|
||||
SortDirection.Descending);
|
||||
|
||||
if (movieIds?.Any() == true)
|
||||
{
|
||||
|
||||
@@ -65,15 +65,15 @@ namespace Radarr.Api.V3.History
|
||||
{
|
||||
var pagingResource = new PagingResource<HistoryResource>(paging);
|
||||
var pagingSpec = pagingResource.MapToPagingSpec<HistoryResource, MovieHistory>(
|
||||
"date",
|
||||
SortDirection.Descending,
|
||||
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"movieMetadata.sortTitle",
|
||||
"languages",
|
||||
"quality",
|
||||
"date"
|
||||
});
|
||||
},
|
||||
"date",
|
||||
SortDirection.Descending);
|
||||
|
||||
if (eventTypes != null && eventTypes.Any())
|
||||
{
|
||||
|
||||
@@ -49,15 +49,15 @@ namespace Radarr.Api.V3.ImportLists
|
||||
{
|
||||
var pagingResource = new PagingResource<ImportListExclusionResource>(paging);
|
||||
var pageSpec = pagingResource.MapToPagingSpec<ImportListExclusionResource, ImportListExclusion>(
|
||||
"id",
|
||||
SortDirection.Descending,
|
||||
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"id",
|
||||
"tmdbId",
|
||||
"movieTitle",
|
||||
"movieYear"
|
||||
});
|
||||
},
|
||||
"id",
|
||||
SortDirection.Descending);
|
||||
|
||||
return pageSpec.ApplyToPage(_importListExclusionService.Paged, ImportListExclusionResourceMapper.ToResource);
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Core.Configuration;
|
||||
@@ -29,7 +31,11 @@ namespace Radarr.Api.V3.Logs
|
||||
}
|
||||
|
||||
var pagingResource = new PagingResource<LogResource>(paging);
|
||||
var pageSpec = pagingResource.MapToPagingSpec<LogResource, Log>();
|
||||
var pageSpec = pagingResource.MapToPagingSpec<LogResource, Log>(new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"id",
|
||||
"time"
|
||||
});
|
||||
|
||||
if (pageSpec.SortKey == "time")
|
||||
{
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Radarr.Api.V3.Queue
|
||||
public PagingResource<QueueResource> GetQueue([FromQuery] PagingRequestResource paging, bool includeUnknownMovieItems = false, bool includeMovie = false, [FromQuery] int[] movieIds = null, DownloadProtocol? protocol = null, [FromQuery] int[] languages = null, int? quality = null)
|
||||
{
|
||||
var pagingResource = new PagingResource<QueueResource>(paging);
|
||||
var pagingSpec = pagingResource.MapToPagingSpec<QueueResource, NzbDrone.Core.Queue.Queue>("timeleft", SortDirection.Ascending);
|
||||
var pagingSpec = pagingResource.MapToPagingSpec<QueueResource, NzbDrone.Core.Queue.Queue>(null, "timeleft", SortDirection.Ascending);
|
||||
|
||||
return pagingSpec.ApplyToPage((spec) => GetQueue(spec, movieIds?.ToHashSet(), protocol, languages?.ToHashSet(), quality, includeUnknownMovieItems), (q) => MapToResource(q, includeMovie));
|
||||
}
|
||||
|
||||
@@ -47,8 +47,6 @@ namespace Radarr.Api.V3.Wanted
|
||||
{
|
||||
var pagingResource = new PagingResource<MovieResource>(paging);
|
||||
var pagingSpec = pagingResource.MapToPagingSpec<MovieResource, Movie>(
|
||||
"movieMetadata.sortTitle",
|
||||
SortDirection.Ascending,
|
||||
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"movieMetadata.sortTitle",
|
||||
@@ -57,7 +55,9 @@ namespace Radarr.Api.V3.Wanted
|
||||
"movieMetadata.digitalRelease",
|
||||
"movieMetadata.physicalRelease",
|
||||
"movies.lastSearchTime"
|
||||
});
|
||||
},
|
||||
"movieMetadata.sortTitle",
|
||||
SortDirection.Ascending);
|
||||
|
||||
pagingSpec.FilterExpressions.Add(v => v.Monitored == monitored);
|
||||
|
||||
|
||||
@@ -43,8 +43,6 @@ namespace Radarr.Api.V3.Wanted
|
||||
{
|
||||
var pagingResource = new PagingResource<MovieResource>(paging);
|
||||
var pagingSpec = pagingResource.MapToPagingSpec<MovieResource, Movie>(
|
||||
"movieMetadata.sortTitle",
|
||||
SortDirection.Ascending,
|
||||
new HashSet<string>(StringComparer.OrdinalIgnoreCase)
|
||||
{
|
||||
"movieMetadata.sortTitle",
|
||||
@@ -53,7 +51,9 @@ namespace Radarr.Api.V3.Wanted
|
||||
"movieMetadata.digitalRelease",
|
||||
"movieMetadata.physicalRelease",
|
||||
"movies.lastSearchTime"
|
||||
});
|
||||
},
|
||||
"movieMetadata.sortTitle",
|
||||
SortDirection.Ascending);
|
||||
|
||||
pagingSpec.FilterExpressions.Add(v => v.Monitored == monitored);
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user