Files
Heimdall/src/Heimdall.Api/Controllers/StatsController.cs
T
Arnaud Dartois e17dce1b4f fix(api): StatsController uses IStatsService instead of direct AppDbContext
- Add IStatsService in Application layer
- Add StatsService in Infrastructure layer
- StatsController now injects IStatsService (Clean Architecture compliant)
- StatsResponse DTO added to Application/DTOs
2026-07-17 17:36:14 +00:00

32 lines
967 B
C#

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