using LBPUnion.ProjectLighthouse.Database; using LBPUnion.ProjectLighthouse.Filter; using LBPUnion.ProjectLighthouse.Filter.Filters; using LBPUnion.ProjectLighthouse.Helpers; using LBPUnion.ProjectLighthouse.Servers.API.Responses; using LBPUnion.ProjectLighthouse.Types.Users; using Microsoft.AspNetCore.Mvc; namespace LBPUnion.ProjectLighthouse.Servers.API.Controllers; /// /// A collection of endpoints relating to statistics. /// public class StatisticsEndpoints : ApiEndpointController { private readonly DatabaseContext database; public StatisticsEndpoints(DatabaseContext database) { this.database = database; } /// /// Gets everything that StatisticsHelper provides. /// /// An instance of StatisticsResponse [HttpGet("statistics")] [ProducesResponseType(typeof(StatisticsResponse), StatusCodes.Status200OK)] public async Task GetStatistics() => this.Ok ( new StatisticsResponse { Photos = await StatisticsHelper.PhotoCount(this.database), Slots = await StatisticsHelper.SlotCount(this.database, new SlotQueryBuilder()), Users = await StatisticsHelper.UserCount(this.database), RecentMatches = await StatisticsHelper.RecentMatches(this.database), TeamPicks = await StatisticsHelper.SlotCount(this.database, new SlotQueryBuilder().AddFilter(new TeamPickFilter())), } ); private static readonly List gameVersions = new() { GameVersion.LittleBigPlanet1, GameVersion.LittleBigPlanet2, GameVersion.LittleBigPlanet3, GameVersion.LittleBigPlanetVita, GameVersion.LittleBigPlanetPSP, }; /// /// Get player counts for each individual title /// /// An instance of PlayerCountResponse [HttpGet("playerCount")] [ProducesResponseType(typeof(PlayerCountResponse), StatusCodes.Status200OK)] public async Task GetPlayerCounts() { List gameList = new(); foreach (GameVersion version in gameVersions) { gameList.Add(new PlayerCountObject { Game = version.ToString(), PlayerCount = await StatisticsHelper.RecentMatchesForGame(this.database, version), }); } PlayerCountResponse response = new() { TotalPlayerCount = await StatisticsHelper.RecentMatches(this.database), Games = gameList, }; return this.Ok(response); } }