mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-07-29 16:38:37 +00:00
Fix CategoryWithUser not pulling slots & total slots properly
This commit is contained in:
parent
2a9537e769
commit
c8dc84e029
7 changed files with 74 additions and 5 deletions
|
@ -82,7 +82,19 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
|
||||
Logger.Log("Found category " + category, LoggerLevelCategory.Instance);
|
||||
|
||||
List<Slot> slots = category.GetSlots(this.database, pageStart, pageSize).ToList();
|
||||
List<Slot> slots;
|
||||
int totalSlots;
|
||||
|
||||
if (category is CategoryWithUser categoryWithUser)
|
||||
{
|
||||
slots = categoryWithUser.GetSlots(this.database, user, pageStart, pageSize).ToList();
|
||||
totalSlots = categoryWithUser.GetTotalSlots(this.database, user);
|
||||
}
|
||||
else
|
||||
{
|
||||
slots = category.GetSlots(this.database, pageStart, pageSize).ToList();
|
||||
totalSlots = category.GetTotalSlots(this.database);
|
||||
}
|
||||
|
||||
string slotsSerialized = slots.Aggregate(string.Empty, (current, slot) => current + slot.Serialize());
|
||||
|
||||
|
@ -95,7 +107,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
new Dictionary<string, object>
|
||||
{
|
||||
{
|
||||
"total", category.GetTotalSlots(this.database)
|
||||
"total", totalSlots
|
||||
},
|
||||
{
|
||||
"hint_start", pageStart + pageSize
|
||||
|
|
|
@ -12,6 +12,20 @@ namespace LBPUnion.ProjectLighthouse.Helpers
|
|||
Categories.Add(new TeamPicksCategory());
|
||||
Categories.Add(new NewestLevelsCategory());
|
||||
Categories.Add(new QueueCategory());
|
||||
Categories.Add
|
||||
(
|
||||
new CustomCategory
|
||||
(
|
||||
"Custom Category",
|
||||
"This is a custom category!",
|
||||
"custom1",
|
||||
"g820614",
|
||||
new[]
|
||||
{
|
||||
35, 37, 2979, 3042,
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -30,6 +30,16 @@ public abstract class CategoryWithUser : Category
|
|||
return -1;
|
||||
}
|
||||
|
||||
public abstract IEnumerable<Slot> GetSlots(Database database, User user, int pageStart, int pageSize);
|
||||
public override IEnumerable<Slot> GetSlots(Database database, int pageStart, int pageSize)
|
||||
{
|
||||
#if DEBUG
|
||||
Logger.Log("tried to get slots without user on CategoryWithUser", LoggerLevelCategory.Instance);
|
||||
if (Debugger.IsAttached) Debugger.Break();
|
||||
#endif
|
||||
return new List<Slot>();
|
||||
}
|
||||
|
||||
public new string Serialize(Database database)
|
||||
{
|
||||
Logger.Log("tried to serialize without user on CategoryWithUser", LoggerLevelCategory.Instance);
|
||||
|
|
31
ProjectLighthouse/Types/Categories/CustomCategory.cs
Normal file
31
ProjectLighthouse/Types/Categories/CustomCategory.cs
Normal file
|
@ -0,0 +1,31 @@
|
|||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Types.Categories
|
||||
{
|
||||
public class CustomCategory : Category
|
||||
{
|
||||
public CustomCategory(string name, string description, string endpoint, string icon, IEnumerable<int> slotIds)
|
||||
{
|
||||
this.Name = name;
|
||||
this.Description = description;
|
||||
this.IconHash = icon;
|
||||
this.Endpoint = endpoint;
|
||||
|
||||
this.SlotIds = slotIds.ToList();
|
||||
}
|
||||
|
||||
public List<int> SlotIds;
|
||||
|
||||
public sealed override string Name { get; set; }
|
||||
public sealed override string Description { get; set; }
|
||||
public sealed override string IconHash { get; set; }
|
||||
public sealed override string Endpoint { get; set; }
|
||||
public override Slot? GetPreviewSlot(Database database) => database.Slots.FirstOrDefault(s => s.SlotId == this.SlotIds[0]);
|
||||
public override IEnumerable<Slot> GetSlots(Database database, int pageStart, int pageSize)
|
||||
=> database.Slots.Where(s => this.SlotIds.Contains(s.SlotId));
|
||||
public override int GetTotalSlots(Database database) => this.SlotIds.Count;
|
||||
}
|
||||
}
|
|
@ -15,7 +15,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
|
|||
public override Slot? GetPreviewSlot(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault();
|
||||
public override IEnumerable<Slot> GetSlots
|
||||
(Database database, int pageStart, int pageSize)
|
||||
=> database.Slots.OrderByDescending(s => s.FirstUploaded).Skip(pageStart).Take(Math.Min(pageSize, 20));
|
||||
=> database.Slots.OrderByDescending(s => s.FirstUploaded).Skip(pageStart - 1).Take(Math.Min(pageSize, 20));
|
||||
public override int GetTotalSlots(Database database) => database.Slots.Count();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
@ -13,10 +14,11 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
|
|||
public override string IconHash { get; set; } = "g820614";
|
||||
|
||||
public override string Endpoint { get; set; } = "queue";
|
||||
public override IEnumerable<Slot> GetSlots(Database database, int pageStart, int pageSize) => new List<Slot>();
|
||||
|
||||
public override Slot? GetPreviewSlot(Database database, User user)
|
||||
=> database.QueuedLevels.Include(q => q.Slot).FirstOrDefault(q => q.UserId == user.UserId)?.Slot;
|
||||
public override IEnumerable<Slot> GetSlots(Database database, User user, int pageStart, int pageSize)
|
||||
=> database.QueuedLevels.Include(q => q.Slot).Include(q => q.Slot.Location).Select(q => q.Slot).Skip(pageStart - 1).Take(Math.Min(pageSize, 20));
|
||||
|
||||
public override int GetTotalSlots(Database database, User user) => database.QueuedLevels.Count(q => q.UserId == user.UserId);
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
|
|||
public override Slot? GetPreviewSlot(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault(s => s.TeamPick);
|
||||
public override IEnumerable<Slot> GetSlots
|
||||
(Database database, int pageStart, int pageSize)
|
||||
=> database.Slots.OrderByDescending(s => s.FirstUploaded).Where(s => s.TeamPick).Skip(pageStart).Take(Math.Min(pageSize, 20));
|
||||
=> database.Slots.OrderByDescending(s => s.FirstUploaded).Where(s => s.TeamPick).Skip(pageStart - 1).Take(Math.Min(pageSize, 20));
|
||||
public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.TeamPick);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue