From d3a0d392ee639266680c0a248f41bf4277ed93d4 Mon Sep 17 00:00:00 2001 From: jvyden Date: Mon, 6 Nov 2023 17:55:27 -0500 Subject: [PATCH] Add pagination to LBP3 categories, fix LevelFilterSettings.GameVersion not getting set --- .../Levels/FilterSettings/LevelFilterSettings.cs | 4 ++-- .../Endpoints/Game/Levels/LevelEndpoints.cs | 12 ++++++++++-- .../Types/Levels/Categories/SerializedCategory.cs | 2 +- .../Types/Lists/SerializedCategoryList.cs | 4 ++-- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/Refresh.GameServer/Endpoints/Game/Levels/FilterSettings/LevelFilterSettings.cs b/Refresh.GameServer/Endpoints/Game/Levels/FilterSettings/LevelFilterSettings.cs index db62aeb4..54ec9dbd 100644 --- a/Refresh.GameServer/Endpoints/Game/Levels/FilterSettings/LevelFilterSettings.cs +++ b/Refresh.GameServer/Endpoints/Game/Levels/FilterSettings/LevelFilterSettings.cs @@ -47,13 +47,13 @@ public class LevelFilterSettings public LevelFilterSettings(TokenGame game) { + this.GameVersion = game; } /// /// Gets the filter settings from a request /// - /// - public LevelFilterSettings(RequestContext context, TokenGame game) + public LevelFilterSettings(RequestContext context, TokenGame game) : this(game) { string[]? gameFilters = context.QueryString.GetValues(context.IsApi() ? "gameFilter" : "gameFilter[]"); if (gameFilters != null) diff --git a/Refresh.GameServer/Endpoints/Game/Levels/LevelEndpoints.cs b/Refresh.GameServer/Endpoints/Game/Levels/LevelEndpoints.cs index b89f2dd6..e04ae875 100644 --- a/Refresh.GameServer/Endpoints/Game/Levels/LevelEndpoints.cs +++ b/Refresh.GameServer/Endpoints/Game/Levels/LevelEndpoints.cs @@ -108,11 +108,19 @@ public class LevelEndpoints : EndpointGroup [MinimumRole(GameUserRole.Restricted)] public SerializedCategoryList GetModernCategories(RequestContext context, GameDatabaseContext database, CategoryService categoryService, MatchService matchService, GameUser user, Token token) { + (int skip, int count) = context.GetPageData(); + IEnumerable categories = categoryService.Categories .Where(c => !c.Hidden) - .Select(c => SerializedCategory.FromLevelCategory(c, context, database, user, token, matchService, 0, 1)); + .Select(c => SerializedCategory.FromLevelCategory(c, context, database, user, token, matchService, 0, 1)) + .Where(c => c.Levels.Total > 0) + .ToList(); + + int total = categories.Count(); + + categories = categories.Skip(skip).Take(count); - return new SerializedCategoryList(categories, categoryService); + return new SerializedCategoryList(categories, total); } [GameEndpoint("searches/{apiRoute}", ContentType.Xml)] diff --git a/Refresh.GameServer/Types/Levels/Categories/SerializedCategory.cs b/Refresh.GameServer/Types/Levels/Categories/SerializedCategory.cs index 6fadb987..8e6378ea 100644 --- a/Refresh.GameServer/Types/Levels/Categories/SerializedCategory.cs +++ b/Refresh.GameServer/Types/Levels/Categories/SerializedCategory.cs @@ -45,7 +45,7 @@ public static SerializedCategory FromLevelCategory(LevelCategory levelCategory, Tag = "", IconHash = levelCategory.IconHash, }; - + DatabaseList categoryLevels = levelCategory.Fetch(context, skip, count, matchService, database, user, new LevelFilterSettings(context, token.TokenGame)); IEnumerable levels = categoryLevels?.Items diff --git a/Refresh.GameServer/Types/Lists/SerializedCategoryList.cs b/Refresh.GameServer/Types/Lists/SerializedCategoryList.cs index 9cb1efe6..49086cd5 100644 --- a/Refresh.GameServer/Types/Lists/SerializedCategoryList.cs +++ b/Refresh.GameServer/Types/Lists/SerializedCategoryList.cs @@ -6,10 +6,10 @@ namespace Refresh.GameServer.Types.Lists; [XmlType("categories")] public class SerializedCategoryList : SerializedList { - public SerializedCategoryList(IEnumerable items, CategoryService categories) + public SerializedCategoryList(IEnumerable items, int total) { this.Items = items.ToList(); - this.Total = categories.Categories.Count(); + this.Total = total; } public SerializedCategoryList() {}