mirror of
https://github.com/LBPUnion/ProjectLighthouse.git
synced 2025-04-19 19:14:51 +00:00
66 lines
No EOL
2 KiB
C#
66 lines
No EOL
2 KiB
C#
#nullable enable
|
|
using LBPUnion.ProjectLighthouse.Levels;
|
|
using LBPUnion.ProjectLighthouse.PlayerData.Profiles;
|
|
using LBPUnion.ProjectLighthouse.Types;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace LBPUnion.ProjectLighthouse.Servers.Website.Controllers.Admin;
|
|
|
|
[ApiController]
|
|
[Route("admin/slot/{id:int}")]
|
|
public class AdminSlotController : ControllerBase
|
|
{
|
|
private readonly Database database;
|
|
|
|
public AdminSlotController(Database database)
|
|
{
|
|
this.database = database;
|
|
}
|
|
|
|
[HttpGet("teamPick")]
|
|
public async Task<IActionResult> TeamPick([FromRoute] int id)
|
|
{
|
|
User? user = this.database.UserFromWebRequest(this.Request);
|
|
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
|
|
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
|
if (slot == null) return this.NotFound();
|
|
|
|
slot.TeamPick = true;
|
|
|
|
await this.database.SaveChangesAsync();
|
|
|
|
return this.Ok();
|
|
}
|
|
|
|
[HttpGet("removeTeamPick")]
|
|
public async Task<IActionResult> RemoveTeamPick([FromRoute] int id)
|
|
{
|
|
User? user = this.database.UserFromWebRequest(this.Request);
|
|
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
|
|
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
|
if (slot == null) return this.NotFound();
|
|
|
|
slot.TeamPick = false;
|
|
|
|
await this.database.SaveChangesAsync();
|
|
|
|
return this.Ok();
|
|
}
|
|
|
|
[HttpGet("delete")]
|
|
public async Task<IActionResult> DeleteLevel([FromRoute] int id)
|
|
{
|
|
User? user = this.database.UserFromWebRequest(this.Request);
|
|
if (user == null || !user.IsAdmin) return this.StatusCode(403, "");
|
|
|
|
Slot? slot = await this.database.Slots.FirstOrDefaultAsync(s => s.SlotId == id);
|
|
if (slot == null) return this.Ok();
|
|
|
|
await this.database.RemoveSlot(slot);
|
|
|
|
return this.Ok();
|
|
}
|
|
} |