ProjectLighthouse/ProjectLighthouse.Servers.GameServer/Controllers/StatisticsController.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

51 lines
2 KiB
C#

using LBPUnion.ProjectLighthouse.Database;
using LBPUnion.ProjectLighthouse.Helpers;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using LBPUnion.ProjectLighthouse.Extensions;
using LBPUnion.ProjectLighthouse.Filter;
using LBPUnion.ProjectLighthouse.Filter.Filters;
using LBPUnion.ProjectLighthouse.Servers.GameServer.Extensions;
using LBPUnion.ProjectLighthouse.Types.Serialization;
namespace LBPUnion.ProjectLighthouse.Servers.GameServer.Controllers;
[ApiController]
[Authorize]
[Route("LITTLEBIGPLANETPS3_XML/")]
[Produces("text/plain")]
public class StatisticsController : ControllerBase
{
private readonly DatabaseContext database;
public StatisticsController(DatabaseContext database)
{
this.database = database;
}
[HttpGet("playersInPodCount")]
public IActionResult PlayersInPodCount() => this.Ok(StatisticsHelper.RoomCountForPlatform(this.GetToken().Platform).ToString());
[HttpGet("totalPlayerCount")]
public async Task<IActionResult> TotalPlayerCount() => this.Ok((await StatisticsHelper.RecentMatchesForGame(this.database, this.GetToken().GameVersion)).ToString());
[HttpGet("planetStats")]
[Produces("text/xml")]
public async Task<IActionResult> PlanetStats()
{
SlotQueryBuilder defaultFilter = this.GetDefaultFilters(this.GetToken());
int totalSlotCount = await StatisticsHelper.SlotCount(this.database, defaultFilter);
defaultFilter.AddFilter(new TeamPickFilter());
int mmPicksCount = await StatisticsHelper.SlotCount(this.database, defaultFilter);
return this.Ok(new PlanetStatsResponse(totalSlotCount, mmPicksCount));
}
[HttpGet("planetStats/totalLevelCount")]
public async Task<IActionResult> TotalLevelCount()
{
SlotQueryBuilder defaultFilter = this.GetDefaultFilters(this.GetToken());
int totalSlotCount = await StatisticsHelper.SlotCount(this.database, defaultFilter);
return this.Ok(totalSlotCount.ToString());
}
}