2026-07-17 17:36:14 +00:00
|
|
|
using Heimdall.Application.Services;
|
2026-07-17 17:22:33 +00:00
|
|
|
using Heimdall.Infrastructure.Security;
|
|
|
|
|
using Microsoft.AspNetCore.Authorization;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace Heimdall.Api.Controllers;
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/stats")]
|
|
|
|
|
public class StatsController : ControllerBase
|
|
|
|
|
{
|
2026-07-17 17:36:14 +00:00
|
|
|
private readonly IStatsService _statsService;
|
2026-07-17 17:22:33 +00:00
|
|
|
|
2026-07-17 17:36:14 +00:00
|
|
|
public StatsController(IStatsService statsService) => _statsService = statsService;
|
2026-07-17 17:22:33 +00:00
|
|
|
|
|
|
|
|
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteRead)]
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> GetStats(CancellationToken ct)
|
|
|
|
|
{
|
2026-07-17 17:36:14 +00:00
|
|
|
var stats = await _statsService.GetStatsAsync(ct);
|
2026-07-17 17:22:33 +00:00
|
|
|
return Ok(new
|
|
|
|
|
{
|
2026-07-17 17:36:14 +00:00
|
|
|
totalSites = stats.TotalSites,
|
|
|
|
|
totalCameras = stats.TotalCameras,
|
|
|
|
|
totalAgents = stats.TotalAgents,
|
|
|
|
|
onlineAgents = stats.OnlineAgents,
|
|
|
|
|
activeSites = stats.ActiveSites,
|
2026-07-17 17:22:33 +00:00
|
|
|
timestamp = DateTime.UtcNow
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|