#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 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 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 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(); } }