44 lines
1.8 KiB
C#
44 lines
1.8 KiB
C#
using Heimdall.Application.DTOs;
|
|||
|
|
using Heimdall.Application.Services;
|
||
|
|
using Heimdall.Infrastructure.Security;
|
||
|
|
using Microsoft.AspNetCore.Authorization;
|
||
|
|
using Microsoft.AspNetCore.Mvc;
|
||
|
|
using Microsoft.AspNetCore.RateLimiting;
|
||
|
|
|
||
|
|
namespace Heimdall.Api.Controllers;
|
||
|
|
|
||
|
|
[ApiController]
|
||
|
|
[Route("api/stats")]
|
||
|
|
[EnableRateLimiting("Api")]
|
||
|
|
public class StatsController : ControllerBase
|
||
|
|
{
|
||
|
|
private readonly IStatsService _statsService;
|
||
|
|
|
||
|
|
public StatsController(IStatsService statsService) => _statsService = statsService;
|
||
|
|
|
||
|
|
/// <summary>Get system-wide statistics.</summary>
|
||
|
|
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteRead)]
|
||
|
|
[HttpGet]
|
||
|
|
[ProducesResponseType(typeof(StatsResponse), StatusCodes.Status200OK)]
|
||
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
||
|
|
public async Task<IActionResult> GetStats(CancellationToken ct)
|
||
|
|
{
|
||
|
|
var result = await _statsService.GetStatsAsync(ct);
|
||
|
|
if (!result.IsSuccess)
|
||
|
|
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||
|
|
return Ok(new { data = result.Data, timestamp = DateTime.UtcNow });
|
||
|
|
}
|
||
|
|
|
||
|
|
/// <summary>Get agent-specific KPIs for the dashboard.</summary>
|
||
|
|
[Authorize(AuthenticationSchemes = "JwtBearer", Policy = AppPermissions.SiteRead)]
|
||
|
|
[HttpGet("agent-stats")]
|
||
|
|
[ProducesResponseType(typeof(List<AgentStatItem>), StatusCodes.Status200OK)]
|
||
|
|
[ProducesResponseType(typeof(void), StatusCodes.Status400BadRequest)]
|
||
|
|
public async Task<IActionResult> GetAgentStats(CancellationToken ct)
|
||
|
|
{
|
||
|
|
var result = await _statsService.GetAgentStatsAsync(ct);
|
||
|
|
if (!result.IsSuccess)
|
||
|
|
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
|
||
|
|
return Ok(result.Data);
|
||
|
|
}
|
||
|
|
}
|