diff --git a/src/Radarr.Api.V3/Blocklist/BlocklistController.cs b/src/Radarr.Api.V3/Blocklist/BlocklistController.cs index e070902cb..9cca018d6 100644 --- a/src/Radarr.Api.V3/Blocklist/BlocklistController.cs +++ b/src/Radarr.Api.V3/Blocklist/BlocklistController.cs @@ -31,8 +31,6 @@ public PagingResource GetBlocklist([FromQuery] PagingRequestR { var pagingResource = new PagingResource(paging); var pagingSpec = pagingResource.MapToPagingSpec( - "date", - SortDirection.Descending, new HashSet(StringComparer.OrdinalIgnoreCase) { "movieMetadata.sortTitle", @@ -41,7 +39,9 @@ public PagingResource GetBlocklist([FromQuery] PagingRequestR "quality", "date", "indexer" - }); + }, + "date", + SortDirection.Descending); if (movieIds?.Any() == true) { diff --git a/src/Radarr.Api.V3/History/HistoryController.cs b/src/Radarr.Api.V3/History/HistoryController.cs index 0f6d98aea..194d96518 100644 --- a/src/Radarr.Api.V3/History/HistoryController.cs +++ b/src/Radarr.Api.V3/History/HistoryController.cs @@ -65,15 +65,15 @@ public PagingResource GetHistory([FromQuery] PagingRequestResou { var pagingResource = new PagingResource(paging); var pagingSpec = pagingResource.MapToPagingSpec( - "date", - SortDirection.Descending, new HashSet(StringComparer.OrdinalIgnoreCase) { "movieMetadata.sortTitle", "languages", "quality", "date" - }); + }, + "date", + SortDirection.Descending); if (eventTypes != null && eventTypes.Any()) { diff --git a/src/Radarr.Api.V3/ImportLists/ImportListExclusionController.cs b/src/Radarr.Api.V3/ImportLists/ImportListExclusionController.cs index 9a7e8725a..9c2bdea06 100644 --- a/src/Radarr.Api.V3/ImportLists/ImportListExclusionController.cs +++ b/src/Radarr.Api.V3/ImportLists/ImportListExclusionController.cs @@ -49,15 +49,15 @@ public PagingResource GetImportListExclusionsPaged( { var pagingResource = new PagingResource(paging); var pageSpec = pagingResource.MapToPagingSpec( - "id", - SortDirection.Descending, new HashSet(StringComparer.OrdinalIgnoreCase) { "id", "tmdbId", "movieTitle", "movieYear" - }); + }, + "id", + SortDirection.Descending); return pageSpec.ApplyToPage(_importListExclusionService.Paged, ImportListExclusionResourceMapper.ToResource); } diff --git a/src/Radarr.Api.V3/Logs/LogController.cs b/src/Radarr.Api.V3/Logs/LogController.cs index 0912fd22c..f6ed810bf 100644 --- a/src/Radarr.Api.V3/Logs/LogController.cs +++ b/src/Radarr.Api.V3/Logs/LogController.cs @@ -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 @@ public PagingResource GetLogs([FromQuery] PagingRequestResource pag } var pagingResource = new PagingResource(paging); - var pageSpec = pagingResource.MapToPagingSpec(); + var pageSpec = pagingResource.MapToPagingSpec(new HashSet(StringComparer.OrdinalIgnoreCase) + { + "id", + "time" + }); if (pageSpec.SortKey == "time") { diff --git a/src/Radarr.Api.V3/Queue/QueueController.cs b/src/Radarr.Api.V3/Queue/QueueController.cs index 5b2e15311..9d649112b 100644 --- a/src/Radarr.Api.V3/Queue/QueueController.cs +++ b/src/Radarr.Api.V3/Queue/QueueController.cs @@ -139,7 +139,7 @@ public object RemoveMany([FromBody] QueueBulkResource resource, [FromQuery] bool public PagingResource 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(paging); - var pagingSpec = pagingResource.MapToPagingSpec("timeleft", SortDirection.Ascending); + var pagingSpec = pagingResource.MapToPagingSpec(null, "timeleft", SortDirection.Ascending); return pagingSpec.ApplyToPage((spec) => GetQueue(spec, movieIds?.ToHashSet(), protocol, languages?.ToHashSet(), quality, includeUnknownMovieItems), (q) => MapToResource(q, includeMovie)); } diff --git a/src/Radarr.Api.V3/Wanted/CutoffController.cs b/src/Radarr.Api.V3/Wanted/CutoffController.cs index 3d02de570..5503a3bb7 100644 --- a/src/Radarr.Api.V3/Wanted/CutoffController.cs +++ b/src/Radarr.Api.V3/Wanted/CutoffController.cs @@ -47,8 +47,6 @@ public PagingResource GetCutoffUnmetMovies([FromQuery] PagingRequ { var pagingResource = new PagingResource(paging); var pagingSpec = pagingResource.MapToPagingSpec( - "movieMetadata.sortTitle", - SortDirection.Ascending, new HashSet(StringComparer.OrdinalIgnoreCase) { "movieMetadata.sortTitle", @@ -57,7 +55,9 @@ public PagingResource GetCutoffUnmetMovies([FromQuery] PagingRequ "movieMetadata.digitalRelease", "movieMetadata.physicalRelease", "movies.lastSearchTime" - }); + }, + "movieMetadata.sortTitle", + SortDirection.Ascending); pagingSpec.FilterExpressions.Add(v => v.Monitored == monitored); diff --git a/src/Radarr.Api.V3/Wanted/MissingController.cs b/src/Radarr.Api.V3/Wanted/MissingController.cs index dd0172485..eeccbb515 100644 --- a/src/Radarr.Api.V3/Wanted/MissingController.cs +++ b/src/Radarr.Api.V3/Wanted/MissingController.cs @@ -43,8 +43,6 @@ public PagingResource GetMissingMovies([FromQuery] PagingRequestR { var pagingResource = new PagingResource(paging); var pagingSpec = pagingResource.MapToPagingSpec( - "movieMetadata.sortTitle", - SortDirection.Ascending, new HashSet(StringComparer.OrdinalIgnoreCase) { "movieMetadata.sortTitle", @@ -53,7 +51,9 @@ public PagingResource GetMissingMovies([FromQuery] PagingRequestR "movieMetadata.digitalRelease", "movieMetadata.physicalRelease", "movies.lastSearchTime" - }); + }, + "movieMetadata.sortTitle", + SortDirection.Ascending); pagingSpec.FilterExpressions.Add(v => v.Monitored == monitored); diff --git a/src/Radarr.Http/PagingResource.cs b/src/Radarr.Http/PagingResource.cs index 72d097364..89f677f18 100644 --- a/src/Radarr.Http/PagingResource.cs +++ b/src/Radarr.Http/PagingResource.cs @@ -40,9 +40,9 @@ public static class PagingResourceMapper { public static PagingSpec MapToPagingSpec( this PagingResource pagingResource, - string defaultSortKey = "Id", - SortDirection defaultSortDirection = SortDirection.Ascending, - HashSet allowedSortKeys = null) + HashSet allowedSortKeys, + string defaultSortKey = "id", + SortDirection defaultSortDirection = SortDirection.Ascending) { var pagingSpec = new PagingSpec { @@ -52,21 +52,15 @@ public static PagingSpec MapToPagingSpec( 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; }