#nullable enable using LBPUnion.ProjectLighthouse.Configuration; using LBPUnion.ProjectLighthouse.Levels; using LBPUnion.ProjectLighthouse.Servers.API.Responses; using LBPUnion.ProjectLighthouse.Types; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; namespace LBPUnion.ProjectLighthouse.Servers.API.Controllers; /// /// A collection of endpoints relating to slots. /// public class SlotEndpoints : ApiEndpointController { private readonly Database database; public SlotEndpoints(Database database) { this.database = database; } /// /// Gets a list of (stripped down) slots from the database. /// /// How many slots you want to retrieve. /// How many slots to skip. /// The slot /// The slot list, if successful. [HttpGet("slots")] [ProducesResponseType(typeof(List), StatusCodes.Status200OK)] public async Task GetSlots([FromQuery] int limit = 20, [FromQuery] int skip = 0) { limit = Math.Min(ServerStatics.PageSize, limit); IEnumerable minimalSlots = (await this.database.Slots.OrderByDescending(s => s.FirstUploaded).Skip(skip).Take(limit).ToListAsync()).Select (MinimalSlot.FromSlot); return this.Ok(minimalSlots); } /// /// Gets a slot (more commonly known as a level) and its information from the database. /// /// The ID of the slot /// The slot /// The slot, if successful. /// The slot could not be found. [HttpGet("slot/{id:int}")] [ProducesResponseType(typeof(Slot), StatusCodes.Status200OK)] [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task GetSlot(int id) { Slot? slot = await this.database.Slots.FirstOrDefaultAsync(u => u.SlotId == id); if (slot == null) return this.NotFound(); return this.Ok(slot); } }