diff --git a/DysonNetwork.Pass/Account/MagicSpellController.cs b/DysonNetwork.Pass/Account/MagicSpellController.cs index 0e3f3b3..a5bd691 100644 --- a/DysonNetwork.Pass/Account/MagicSpellController.cs +++ b/DysonNetwork.Pass/Account/MagicSpellController.cs @@ -1,3 +1,5 @@ +using DysonNetwork.Shared.Models; +using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; @@ -7,17 +9,31 @@ namespace DysonNetwork.Pass.Account; [Route("/api/spells")] public class MagicSpellController(AppDatabase db, MagicSpellService sp) : ControllerBase { + [HttpPost("activation/resend")] + [Authorize] + public async Task ResendActivationMagicSpell() + { + if (HttpContext.Items["CurrentUser"] is not SnAccount currentUser) return Unauthorized(); + + var spell = await db.MagicSpells.FirstOrDefaultAsync(s => + s.Type == MagicSpellType.AccountActivation && s.AccountId == currentUser.Id); + if (spell is null) return BadRequest("Unable to find activation magic spell."); + + await sp.NotifyMagicSpell(spell, true); + return Ok(); + } + [HttpPost("{spellId:guid}/resend")] public async Task ResendMagicSpell(Guid spellId) { var spell = db.MagicSpells.FirstOrDefault(x => x.Id == spellId); if (spell == null) return NotFound(); - + await sp.NotifyMagicSpell(spell, true); return Ok(); } - + [HttpGet("{spellWord}")] public async Task GetMagicSpell(string spellWord) { @@ -38,7 +54,8 @@ public class MagicSpellController(AppDatabase db, MagicSpellService sp) : Contro } [HttpPost("{spellWord}/apply")] - public async Task ApplyMagicSpell([FromRoute] string spellWord, [FromBody] MagicSpellApplyRequest? request) + public async Task ApplyMagicSpell([FromRoute] string spellWord, + [FromBody] MagicSpellApplyRequest? request) { var word = Uri.UnescapeDataString(spellWord); var spell = await db.MagicSpells @@ -59,6 +76,7 @@ public class MagicSpellController(AppDatabase db, MagicSpellService sp) : Contro { return BadRequest(ex.Message); } + return Ok(); } } \ No newline at end of file