1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-20 01:42:35 +01: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

@ -31,8 +31,6 @@ public PagingResource<BlocklistResource> GetBlocklist([FromQuery] PagingRequestR
{
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 @@ public PagingResource<BlocklistResource> GetBlocklist([FromQuery] PagingRequestR
"quality",
"date",
"indexer"
});
},
"date",
SortDirection.Descending);
if (movieIds?.Any() == true)
{

View File

@ -65,15 +65,15 @@ public PagingResource<HistoryResource> GetHistory([FromQuery] PagingRequestResou
{
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())
{

View File

@ -49,15 +49,15 @@ public PagingResource<ImportListExclusionResource> GetImportListExclusionsPaged(
{
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);
}

View File

@ -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<LogResource> GetLogs([FromQuery] PagingRequestResource pag
}
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")
{

View File

@ -139,7 +139,7 @@ public object RemoveMany([FromBody] QueueBulkResource resource, [FromQuery] bool
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));
}

View File

@ -47,8 +47,6 @@ public PagingResource<MovieResource> GetCutoffUnmetMovies([FromQuery] PagingRequ
{
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 @@ public PagingResource<MovieResource> GetCutoffUnmetMovies([FromQuery] PagingRequ
"movieMetadata.digitalRelease",
"movieMetadata.physicalRelease",
"movies.lastSearchTime"
});
},
"movieMetadata.sortTitle",
SortDirection.Ascending);
pagingSpec.FilterExpressions.Add(v => v.Monitored == monitored);

View File

@ -43,8 +43,6 @@ public PagingResource<MovieResource> GetMissingMovies([FromQuery] PagingRequestR
{
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 @@ public PagingResource<MovieResource> GetMissingMovies([FromQuery] PagingRequestR
"movieMetadata.digitalRelease",
"movieMetadata.physicalRelease",
"movies.lastSearchTime"
});
},
"movieMetadata.sortTitle",
SortDirection.Ascending);
pagingSpec.FilterExpressions.Add(v => v.Monitored == monitored);

View File

@ -40,9 +40,9 @@ public static class PagingResourceMapper
{
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 @@ public static PagingSpec<TModel> MapToPagingSpec<TResource, TModel>(
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;
}