✨ Added magic spell page
This commit is contained in:
28
DysonNetwork.Pass/Pages/Data/SpellPageData.cs
Normal file
28
DysonNetwork.Pass/Pages/Data/SpellPageData.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using DysonNetwork.Shared.PageData;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using NodaTime;
|
||||
|
||||
namespace DysonNetwork.Pass.Pages.Data;
|
||||
|
||||
public class SpellPageData(AppDatabase db) : IPageDataProvider
|
||||
{
|
||||
public bool CanHandlePath(PathString path) => path.StartsWithSegments("/spells");
|
||||
|
||||
public async Task<IDictionary<string, object?>> GetAppDataAsync(HttpContext context)
|
||||
{
|
||||
var spellWord = context.Request.Path.Value!.Split('/').Last();
|
||||
spellWord = Uri.UnescapeDataString(spellWord);
|
||||
var now = SystemClock.Instance.GetCurrentInstant();
|
||||
var spell = await db.MagicSpells
|
||||
.Where(e => e.Spell == spellWord)
|
||||
.Where(e => e.ExpiresAt == null || now < e.ExpiresAt)
|
||||
.Where(e => e.AffectedAt == null || now >= e.AffectedAt)
|
||||
.Include(e => e.Account)
|
||||
.ThenInclude(e => e.Profile)
|
||||
.FirstOrDefaultAsync();
|
||||
return new Dictionary<string, object?>
|
||||
{
|
||||
["Spell"] = spell
|
||||
};
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user