Skip to content

Commit

Permalink
Add pagination to LBP3 categories, fix LevelFilterSettings.GameVersio…
Browse files Browse the repository at this point in the history
…n not getting set
  • Loading branch information
jvyden committed Nov 6, 2023
1 parent e4e50ca commit d3a0d39
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ public class LevelFilterSettings

public LevelFilterSettings(TokenGame game)
{
this.GameVersion = game;
}

/// <summary>
/// Gets the filter settings from a request
/// </summary>
/// <param name="context"></param>
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)
Expand Down
12 changes: 10 additions & 2 deletions Refresh.GameServer/Endpoints/Game/Levels/LevelEndpoints.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<SerializedCategory> 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)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static SerializedCategory FromLevelCategory(LevelCategory levelCategory,
Tag = "",
IconHash = levelCategory.IconHash,
};

DatabaseList<GameLevel> categoryLevels = levelCategory.Fetch(context, skip, count, matchService, database, user, new LevelFilterSettings(context, token.TokenGame));

IEnumerable<GameMinimalLevelResponse> levels = categoryLevels?.Items
Expand Down
4 changes: 2 additions & 2 deletions Refresh.GameServer/Types/Lists/SerializedCategoryList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ namespace Refresh.GameServer.Types.Lists;
[XmlType("categories")]
public class SerializedCategoryList : SerializedList<SerializedCategory>
{
public SerializedCategoryList(IEnumerable<SerializedCategory> items, CategoryService categories)
public SerializedCategoryList(IEnumerable<SerializedCategory> items, int total)
{
this.Items = items.ToList();
this.Total = categories.Categories.Count();
this.Total = total;
}

public SerializedCategoryList() {}
Expand Down

0 comments on commit d3a0d39

Please sign in to comment.