aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien Meur <damien.meur@tmonier.com>2026-07-14 02:57:15 +0200
committerDamien Meur <damien.meur@tmonier.com>2026-07-14 02:57:15 +0200
commit56c970c2db491b80e14ceca4c115cfb72b75365c (patch)
tree7bf9fa9e76be987d33d45f54d3c4b660da50ed84
parentcfeaef61806525f85ad42f95961e1294a66e7944 (diff)
Make RequestHelpers.GetOrderBy generic and reuse it in ActivityLogController
-rw-r--r--Jellyfin.Api/Controllers/ActivityLogController.cs31
-rw-r--r--Jellyfin.Api/Helpers/RequestHelpers.cs8
2 files changed, 6 insertions, 33 deletions
diff --git a/Jellyfin.Api/Controllers/ActivityLogController.cs b/Jellyfin.Api/Controllers/ActivityLogController.cs
index d6cc0e71a4..8e17dd7d53 100644
--- a/Jellyfin.Api/Controllers/ActivityLogController.cs
+++ b/Jellyfin.Api/Controllers/ActivityLogController.cs
@@ -1,6 +1,6 @@
using System;
-using System.Collections.Generic;
using System.Threading.Tasks;
+using Jellyfin.Api.Helpers;
using Jellyfin.Data.Enums;
using Jellyfin.Data.Queries;
using Jellyfin.Database.Implementations.Enums;
@@ -84,36 +84,9 @@ public class ActivityLogController : BaseJellyfinApiController
ItemId = itemId,
Username = username,
Severity = severity,
- OrderBy = GetOrderBy(sortBy ?? [], sortOrder ?? []),
+ OrderBy = RequestHelpers.GetOrderBy(sortBy ?? [], sortOrder ?? []),
};
return await _activityManager.GetPagedResultAsync(query).ConfigureAwait(false);
}
-
- private static (ActivityLogSortBy SortBy, SortOrder SortOrder)[] GetOrderBy(
- IReadOnlyList<ActivityLogSortBy> sortBy,
- IReadOnlyList<SortOrder> requestedSortOrder)
- {
- if (sortBy.Count == 0)
- {
- return [];
- }
-
- var result = new (ActivityLogSortBy, SortOrder)[sortBy.Count];
- var i = 0;
- for (; i < requestedSortOrder.Count; i++)
- {
- result[i] = (sortBy[i], requestedSortOrder[i]);
- }
-
- // Add remaining elements with the first specified SortOrder
- // or the default one if no SortOrders are specified
- var order = requestedSortOrder.Count > 0 ? requestedSortOrder[0] : SortOrder.Ascending;
- for (; i < sortBy.Count; i++)
- {
- result[i] = (sortBy[i], order);
- }
-
- return result;
- }
}
diff --git a/Jellyfin.Api/Helpers/RequestHelpers.cs b/Jellyfin.Api/Helpers/RequestHelpers.cs
index 5072f902da..d14c3a9343 100644
--- a/Jellyfin.Api/Helpers/RequestHelpers.cs
+++ b/Jellyfin.Api/Helpers/RequestHelpers.cs
@@ -5,7 +5,6 @@ using System.Security.Claims;
using System.Threading.Tasks;
using Jellyfin.Api.Constants;
using Jellyfin.Api.Extensions;
-using Jellyfin.Data.Enums;
using Jellyfin.Database.Implementations.Entities;
using Jellyfin.Database.Implementations.Enums;
using Jellyfin.Extensions;
@@ -31,15 +30,16 @@ public static class RequestHelpers
/// </summary>
/// <param name="sortBy">Sort By. Comma delimited string.</param>
/// <param name="requestedSortOrder">Sort Order. Comma delimited string.</param>
+ /// <typeparam name="TSortBy">The type of the sort by field.</typeparam>
/// <returns>Order By.</returns>
- public static (ItemSortBy, SortOrder)[] GetOrderBy(IReadOnlyList<ItemSortBy> sortBy, IReadOnlyList<SortOrder> requestedSortOrder)
+ public static (TSortBy, SortOrder)[] GetOrderBy<TSortBy>(IReadOnlyList<TSortBy> sortBy, IReadOnlyList<SortOrder> requestedSortOrder)
{
if (sortBy.Count == 0)
{
- return Array.Empty<(ItemSortBy, SortOrder)>();
+ return Array.Empty<(TSortBy, SortOrder)>();
}
- var result = new (ItemSortBy, SortOrder)[sortBy.Count];
+ var result = new (TSortBy, SortOrder)[sortBy.Count];
var i = 0;
// Add elements which have a SortOrder specified
for (; i < requestedSortOrder.Count; i++)