mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-08-22 18:31:30 +00:00
Implement callback urls when hearting/queueing levels on the web
This commit is contained in:
parent
3d39bfedb6
commit
45d7532292
2 changed files with 37 additions and 12 deletions
|
@ -5,6 +5,11 @@ using LBPUnion.ProjectLighthouse.Types.Levels;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
// I would like to apologize in advance for anyone dealing with this file.
|
||||||
|
// Theres probably a better way to do this with delegates but I'm tired.
|
||||||
|
// TODO: Clean up this file
|
||||||
|
// - jvyden
|
||||||
|
|
||||||
namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
||||||
{
|
{
|
||||||
[ApiController]
|
[ApiController]
|
||||||
|
@ -19,8 +24,13 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("heart")]
|
[HttpGet("heart")]
|
||||||
public async Task<IActionResult> HeartLevel([FromRoute] int id)
|
public async Task<IActionResult> HeartLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(callbackUrl))
|
||||||
|
{
|
||||||
|
callbackUrl = "~/slot/" + id;
|
||||||
|
}
|
||||||
|
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
if (user == null) return this.Redirect("~/login");
|
if (user == null) return this.Redirect("~/login");
|
||||||
|
|
||||||
|
@ -29,12 +39,17 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
||||||
|
|
||||||
await this.database.HeartLevel(user, heartedSlot);
|
await this.database.HeartLevel(user, heartedSlot);
|
||||||
|
|
||||||
return this.Redirect("~/slot/" + id);
|
return this.Redirect(callbackUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("unheart")]
|
[HttpGet("unheart")]
|
||||||
public async Task<IActionResult> UnheartLevel([FromRoute] int id)
|
public async Task<IActionResult> UnheartLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(callbackUrl))
|
||||||
|
{
|
||||||
|
callbackUrl = "~/slot/" + id;
|
||||||
|
}
|
||||||
|
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
if (user == null) return this.Redirect("~/login");
|
if (user == null) return this.Redirect("~/login");
|
||||||
|
|
||||||
|
@ -43,12 +58,17 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
||||||
|
|
||||||
await this.database.UnheartLevel(user, heartedSlot);
|
await this.database.UnheartLevel(user, heartedSlot);
|
||||||
|
|
||||||
return this.Redirect("~/slot/" + id);
|
return this.Redirect(callbackUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("queue")]
|
[HttpGet("queue")]
|
||||||
public async Task<IActionResult> QueueLevel([FromRoute] int id)
|
public async Task<IActionResult> QueueLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(callbackUrl))
|
||||||
|
{
|
||||||
|
callbackUrl = "~/slot/" + id;
|
||||||
|
}
|
||||||
|
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
if (user == null) return this.Redirect("~/login");
|
if (user == null) return this.Redirect("~/login");
|
||||||
|
|
||||||
|
@ -57,12 +77,17 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
||||||
|
|
||||||
await this.database.QueueLevel(user, queuedSlot);
|
await this.database.QueueLevel(user, queuedSlot);
|
||||||
|
|
||||||
return this.Redirect("~/slot/" + id);
|
return this.Redirect(callbackUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet("unqueue")]
|
[HttpGet("unqueue")]
|
||||||
public async Task<IActionResult> UnqueueLevel([FromRoute] int id)
|
public async Task<IActionResult> UnqueueLevel([FromRoute] int id, [FromQuery] string? callbackUrl)
|
||||||
{
|
{
|
||||||
|
if (string.IsNullOrEmpty(callbackUrl))
|
||||||
|
{
|
||||||
|
callbackUrl = "~/slot/" + id;
|
||||||
|
}
|
||||||
|
|
||||||
User? user = this.database.UserFromWebRequest(this.Request);
|
User? user = this.database.UserFromWebRequest(this.Request);
|
||||||
if (user == null) return this.Redirect("~/login");
|
if (user == null) return this.Redirect("~/login");
|
||||||
|
|
||||||
|
@ -71,7 +96,7 @@ namespace LBPUnion.ProjectLighthouse.Controllers.Website
|
||||||
|
|
||||||
await this.database.UnqueueLevel(user, queuedSlot);
|
await this.database.UnqueueLevel(user, queuedSlot);
|
||||||
|
|
||||||
return this.Redirect("~/slot/" + id);
|
return this.Redirect(callbackUrl);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -50,26 +50,26 @@
|
||||||
{
|
{
|
||||||
if (isHearted)
|
if (isHearted)
|
||||||
{
|
{
|
||||||
<a class="ui pink tiny button" href="/slot/@slot.SlotId/unheart" title="Unheart">
|
<a class="ui pink tiny button" href="/slot/@slot.SlotId/unheart?callbackUrl=~/slots/@Model.PageNumber" title="Unheart">
|
||||||
<i class="broken heart icon" style="margin: 0"></i>
|
<i class="broken heart icon" style="margin: 0"></i>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<a class="ui pink tiny button" href="/slot/@slot.SlotId/heart" title="Heart">
|
<a class="ui pink tiny button" href="/slot/@slot.SlotId/heart?callbackUrl=~/slots/@Model.PageNumber" title="Heart">
|
||||||
<i class="heart icon" style="margin: 0"></i>
|
<i class="heart icon" style="margin: 0"></i>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isQueued)
|
if (isQueued)
|
||||||
{
|
{
|
||||||
<a class="ui yellow tiny button" href="/slot/@slot.SlotId/unqueue" title="Unqueue">
|
<a class="ui yellow tiny button" href="/slot/@slot.SlotId/unqueue?callbackUrl=~/slots/@Model.PageNumber" title="Unqueue">
|
||||||
<i class="bell slash icon" style="margin: 0"></i>
|
<i class="bell slash icon" style="margin: 0"></i>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
<a class="ui yellow tiny button" href="/slot/@slot.SlotId/queue" title="Queue">
|
<a class="ui yellow tiny button" href="/slot/@slot.SlotId/queue?callbackUrl=~/slots/@Model.PageNumber" title="Queue">
|
||||||
<i class="bell icon" style="margin: 0"></i>
|
<i class="bell icon" style="margin: 0"></i>
|
||||||
</a>
|
</a>
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue