ProjectLighthouse/ProjectLighthouse.Servers.API/Controllers/StatisticsEndpoints.cs
Josh 0c1e350fa3
Rewrite gameserver slot filter system (#763)
* Initial implementation of new slot sorting and filtering system

* Initial implementation of filtering for lbp3 community tab

* Add support for organization on lbp3

* Add playlist and user categories

* Implement unit tests for all filters
Refactor more systems to use PaginationData

* Fix PlayerCountFilter test

* Add more unit tests and integration tests for the filter system

* Fix LBP2 move filter and gameFilterType

* Fix sort by likes in LBP3 category

* Add sort for total plays

* Remove extra whitespace and make styling more consistent

* Order hearted and queued levels by primary key ID

* Fix query without order warnings
2023-05-31 21:33:39 +00:00

77 lines
No EOL
2.6 KiB
C#

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;
/// <summary>
/// A collection of endpoints relating to statistics.
/// </summary>
public class StatisticsEndpoints : ApiEndpointController
{
private readonly DatabaseContext database;
public StatisticsEndpoints(DatabaseContext database)
{
this.database = database;
}
/// <summary>
/// Gets everything that StatisticsHelper provides.
/// </summary>
/// <returns>An instance of StatisticsResponse</returns>
[HttpGet("statistics")]
[ProducesResponseType(typeof(StatisticsResponse), StatusCodes.Status200OK)]
public async Task<IActionResult> 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<GameVersion> gameVersions = new()
{
GameVersion.LittleBigPlanet1,
GameVersion.LittleBigPlanet2,
GameVersion.LittleBigPlanet3,
GameVersion.LittleBigPlanetVita,
GameVersion.LittleBigPlanetPSP,
};
/// <summary>
/// Get player counts for each individual title
/// </summary>
/// <returns>An instance of PlayerCountResponse</returns>
[HttpGet("playerCount")]
[ProducesResponseType(typeof(PlayerCountResponse), StatusCodes.Status200OK)]
public async Task<IActionResult> GetPlayerCounts()
{
List<PlayerCountObject> 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);
}
}