add stats endpoint

This commit is contained in:
Alan Moon 2025-03-14 16:20:13 -07:00
parent 3a58938f59
commit d3b7270dcd

View File

@ -1,9 +1,31 @@
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using sodoff.Model;
namespace sodoff.Controllers.Common namespace sodoff.Controllers.Common
{ {
public class AnalyticsController : Controller public class AnalyticsController : Controller
{ {
private readonly DBContext ctx;
public AnalyticsController(DBContext ctx)
{
this.ctx = ctx;
}
[HttpGet]
[Route("AnalyticsWebService.asmx/GetUserAndVikingCount")]
public IActionResult GetUserAndVikingCount([FromForm] bool vikingsOnly)
{
if (vikingsOnly) return Ok(new UserStatistics
{
VikingCount = ctx.Vikings.Count(e => e.Id > 0)
});
else return Ok(new UserStatistics
{
VikingCount = ctx.Vikings.Count(),
UserCount = ctx.Users.Count(),
});
}
[HttpPost] [HttpPost]
[Produces("application/xml")] [Produces("application/xml")]
[Route("AnalyticsWebService.asmx/LogEvent")] [Route("AnalyticsWebService.asmx/LogEvent")]
@ -20,4 +42,10 @@ namespace sodoff.Controllers.Common
return Ok(); return Ok();
} }
} }
public class UserStatistics
{
public int VikingCount { get; set; }
public int? UserCount { get; set; }
}
} }