mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-01 09:48:37 +00:00
Add QueueCategory
This commit is contained in:
parent
d6a0b7fd9c
commit
f8c02cb3aa
5 changed files with 52 additions and 11 deletions
|
@ -1,7 +1,9 @@
|
|||
#nullable enable
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types;
|
||||
using LBPUnion.ProjectLighthouse.Types.Categories;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
|
@ -26,12 +28,14 @@ namespace LBPUnion.ProjectLighthouse.Controllers
|
|||
[HttpGet("genres")]
|
||||
public async Task<IActionResult> GenresAndSearches()
|
||||
{
|
||||
User? user = await this.database.UserFromGameRequest(this.Request);
|
||||
if (user == null) return this.StatusCode(403, "");
|
||||
|
||||
List<Category> categories = new()
|
||||
{
|
||||
new TeamPicksCategory(),
|
||||
new TeamPicksCategory(),
|
||||
new NewestLevelsCategory(),
|
||||
new NewestLevelsCategory(),
|
||||
new QueueCategory(user),
|
||||
};
|
||||
|
||||
string categoriesSerialized = categories.Aggregate(string.Empty, (current, category) => current + category.Serialize(this.database));
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
#nullable enable
|
||||
using System.Xml.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Serialization;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
@ -28,11 +27,17 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
|
|||
set => this.Endpoint = value.Replace("/searches/", "");
|
||||
}
|
||||
|
||||
public abstract IEnumerable<Slot> Slots(Database database);
|
||||
public abstract Slot? GetPreviewSlot(Database database);
|
||||
|
||||
public string Serialize(Database database)
|
||||
{
|
||||
string slots = this.Slots(database).Aggregate(string.Empty, (current, slot) => current + slot.Serialize());
|
||||
Slot? previewSlot = this.GetPreviewSlot(database);
|
||||
|
||||
string previewResults = "";
|
||||
if (previewSlot != null)
|
||||
{
|
||||
previewResults = LbpSerializer.StringElement("results", LbpSerializer.StringElement("slots", previewSlot.Serialize()));
|
||||
}
|
||||
|
||||
return LbpSerializer.StringElement
|
||||
(
|
||||
|
@ -40,7 +45,7 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
|
|||
LbpSerializer.StringElement("name", this.Name) +
|
||||
LbpSerializer.StringElement("description", this.Description) +
|
||||
LbpSerializer.StringElement("url", this.IngameEndpoint) +
|
||||
LbpSerializer.StringElement("results", slots) +
|
||||
(previewSlot == null ? "" : previewResults) +
|
||||
LbpSerializer.StringElement("icon", IconHash)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
||||
|
@ -10,6 +10,6 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
|
|||
public override string Description { get; set; } = "Levels recently published";
|
||||
public override string IconHash { get; set; } = "g820623";
|
||||
public override string Endpoint { get; set; } = "newest";
|
||||
public override IEnumerable<Slot> Slots(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).Take(1);
|
||||
public override Slot? GetPreviewSlot(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault();
|
||||
}
|
||||
}
|
32
ProjectLighthouse/Types/Categories/QueueCategory.cs
Normal file
32
ProjectLighthouse/Types/Categories/QueueCategory.cs
Normal file
|
@ -0,0 +1,32 @@
|
|||
#nullable enable
|
||||
using System.Linq;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace LBPUnion.ProjectLighthouse.Types.Categories
|
||||
{
|
||||
public class QueueCategory : Category
|
||||
{
|
||||
private User user;
|
||||
|
||||
public QueueCategory(User user)
|
||||
{
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
public override string Name { get; set; } = "My Queue";
|
||||
public override string Description { get; set; } = "Your queued levels";
|
||||
public override string IconHash { get; set; } = "g820614";
|
||||
|
||||
public override string Endpoint {
|
||||
get => $"queue/{this.user.UserId}";
|
||||
set {
|
||||
// cry about it, i don't care
|
||||
}
|
||||
}
|
||||
|
||||
public override Slot? GetPreviewSlot
|
||||
(Database database)
|
||||
=> database.QueuedLevels.Include(q => q.Slot).FirstOrDefault(q => q.UserId == this.user.UserId)?.Slot;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
using System.Collections.Generic;
|
||||
#nullable enable
|
||||
using System.Linq;
|
||||
using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||
|
||||
|
@ -10,6 +10,6 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
|
|||
public override string Description { get; set; } = "Levels given awards by your instance admin";
|
||||
public override string IconHash { get; set; } = "g820626";
|
||||
public override string Endpoint { get; set; } = "team_picks";
|
||||
public override IEnumerable<Slot> Slots(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).Where(s => s.TeamPick).Take(1);
|
||||
public override Slot? GetPreviewSlot(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault(s => s.TeamPick);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue