From 30e5d4e3b57418549a9d6095b60474f1abe484a7 Mon Sep 17 00:00:00 2001 From: jvyden Date: Fri, 29 Oct 2021 19:00:50 -0400 Subject: [PATCH] Add StatisticsController, add /planetStats --- .../Controllers/MatchController.cs | 10 ----- .../Controllers/StatisticsController.cs | 39 +++++++++++++++++++ 2 files changed, 39 insertions(+), 10 deletions(-) create mode 100644 ProjectLighthouse/Controllers/StatisticsController.cs diff --git a/ProjectLighthouse/Controllers/MatchController.cs b/ProjectLighthouse/Controllers/MatchController.cs index 5b14bf76..a5aec1cb 100644 --- a/ProjectLighthouse/Controllers/MatchController.cs +++ b/ProjectLighthouse/Controllers/MatchController.cs @@ -74,15 +74,5 @@ namespace LBPUnion.ProjectLighthouse.Controllers { return this.Ok("[{\"StatusCode\":200}]"); } - - [HttpGet("playersInPodCount")] - [HttpGet("totalPlayerCount")] - public async Task TotalPlayerCount() { - int recentMatches = await this.database.LastMatches - .Where(l => TimestampHelper.Timestamp - l.Timestamp < 60) - .CountAsync(); - - return this.Ok(recentMatches.ToString()); - } } } \ No newline at end of file diff --git a/ProjectLighthouse/Controllers/StatisticsController.cs b/ProjectLighthouse/Controllers/StatisticsController.cs new file mode 100644 index 00000000..d71a9222 --- /dev/null +++ b/ProjectLighthouse/Controllers/StatisticsController.cs @@ -0,0 +1,39 @@ +using System.Linq; +using System.Threading.Tasks; +using LBPUnion.ProjectLighthouse.Helpers; +using LBPUnion.ProjectLighthouse.Serialization; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace LBPUnion.ProjectLighthouse.Controllers { + [ApiController] + [Route("LITTLEBIGPLANETPS3_XML/")] + [Produces("text/plain")] + public class StatisticsController : ControllerBase { + private readonly Database database; + public StatisticsController(Database database) { + this.database = database; + } + + [HttpGet("playersInPodCount")] + [HttpGet("totalPlayerCount")] + public async Task TotalPlayerCount() { + int recentMatches = await this.database.LastMatches + .Where(l => TimestampHelper.Timestamp - l.Timestamp < 60) + .CountAsync(); + + return this.Ok(recentMatches.ToString()); + } + + [HttpGet("planetStats")] + public async Task PlanetStats() { + int totalSlotCount = await this.database.Slots.CountAsync(); + const int mmPicksCount = 0; + + return this.Ok(LbpSerializer.StringElement("planetStats", + LbpSerializer.StringElement("totalSlotCount", totalSlotCount) + + LbpSerializer.StringElement("mmPicksCount", mmPicksCount) + )); + } + } +} \ No newline at end of file