using Cleanuparr.Infrastructure.Stats; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; namespace Cleanuparr.Api.Controllers; /// /// Aggregated statistics endpoint for dashboard integrations. /// Deprecated. Use GET /api/v2/stats instead. /// [ApiController] [Route("api/[controller]")] [Authorize] public class StatsController : ControllerBase { private static readonly DateTimeOffset SunsetDate = new(2026, 9, 1, 0, 0, 0, TimeSpan.Zero); private readonly IStatsService _statsService; public StatsController(IStatsService statsService) { _statsService = statsService; } /// /// Gets aggregated application statistics for the specified timeframe. /// Deprecated. Use GET /api/v2/stats instead. Responses carry Deprecation/Link headers. /// /// Timeframe in hours (default 24, range 1-720) /// Number of recent events to include (0 = none, max 100) /// Number of recent strikes to include (0 = none, max 100) [HttpGet] public async Task GetStats( [FromQuery] int hours = 24, [FromQuery] int includeEvents = 0, [FromQuery] int includeStrikes = 0) { Response.Headers["Deprecation"] = "true"; Response.Headers["Sunset"] = SunsetDate.ToString("R"); Response.Headers["Link"] = "; rel=\"successor-version\", " + "; rel=\"deprecation\""; if (DateTimeOffset.UtcNow >= SunsetDate) { return NotFound(); } hours = Math.Clamp(hours, 1, 720); includeEvents = Math.Clamp(includeEvents, 0, 100); includeStrikes = Math.Clamp(includeStrikes, 0, 100); var stats = await _statsService.GetStatsAsync(hours, includeEvents, includeStrikes); return Ok(stats); } }