Files
Heimdall/src/Heimdall.Web/Controllers/StatsController.cs
T

46 lines
1.8 KiB
C#
Raw Normal View History

using Heimdall.Application.DTOs;
using Heimdall.Application.Stats.Queries.GetStats;
using Heimdall.Application.Stats.Queries.GetAgentStats;
using Heimdall.Infrastructure.Security;
using MediatR;
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 IMediator _mediator;
public StatsController(IMediator mediator) => _mediator = mediator;
/// <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 _mediator.Send(new GetStatsQuery(), 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 _mediator.Send(new GetAgentStatsQuery(), ct);
if (!result.IsSuccess)
return StatusCode(result.StatusCode ?? 400, new { error = result.Error });
return Ok(result.Data);
}
}