Fix category slot serialization bug

This commit is contained in:
jvyden 2021-12-28 17:15:31 -05:00
commit c3d4a97565
No known key found for this signature in database
GPG key ID: 18BCF2BE0262B278
4 changed files with 22 additions and 3 deletions

View file

@ -1,4 +1,5 @@
#nullable enable
using System.Collections.Generic;
using System.Xml.Serialization;
using LBPUnion.ProjectLighthouse.Serialization;
using LBPUnion.ProjectLighthouse.Types.Levels;
@ -29,6 +30,8 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
public abstract Slot? GetPreviewSlot(Database database);
public abstract int GetTotalSlots(Database database);
public string Serialize(Database database)
{
Slot? previewSlot = this.GetPreviewSlot(database);
@ -36,7 +39,20 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
string previewResults = "";
if (previewSlot != null)
{
previewResults = LbpSerializer.StringElement("results", LbpSerializer.StringElement("slots", previewSlot.Serialize()));
previewResults = LbpSerializer.TaggedStringElement
(
"results",
previewSlot.Serialize(),
new Dictionary<string, object>
{
{
"total", this.GetTotalSlots(database)
},
{
"hint_start", "2"
},
}
);
}
return LbpSerializer.StringElement

View file

@ -11,5 +11,6 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
public override string IconHash { get; set; } = "g820623";
public override string Endpoint { get; set; } = "newest";
public override Slot? GetPreviewSlot(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault();
public override int GetTotalSlots(Database database) => database.Slots.Count();
}
}

View file

@ -25,8 +25,9 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
}
}
public override Slot? GetPreviewSlot
(Database database)
public override Slot? GetPreviewSlot(Database database)
=> database.QueuedLevels.Include(q => q.Slot).FirstOrDefault(q => q.UserId == this.user.UserId)?.Slot;
public override int GetTotalSlots(Database database) => database.QueuedLevels.Count(q => q.UserId == this.user.UserId);
}
}

View file

@ -11,5 +11,6 @@ namespace LBPUnion.ProjectLighthouse.Types.Categories
public override string IconHash { get; set; } = "g820626";
public override string Endpoint { get; set; } = "team_picks";
public override Slot? GetPreviewSlot(Database database) => database.Slots.OrderByDescending(s => s.FirstUploaded).FirstOrDefault(s => s.TeamPick);
public override int GetTotalSlots(Database database) => database.Slots.Count(s => s.TeamPick);
}
}