using DeepDrftData; using Microsoft.AspNetCore.Mvc; namespace DeepDrftAPI.Controllers; [ApiController] [Route("api/[controller]")] public class StatsController : ControllerBase { private readonly ITrackService _sqlTrackService; private readonly ILogger _logger; public StatsController(ITrackService sqlTrackService, ILogger logger) { _sqlTrackService = sqlTrackService; _logger = logger; } // GET api/stats/home (unauthenticated) // Aggregate figures behind the public home hero stat row — one read for all three cards. Same auth // posture as the other public browse reads (GET api/track/page). The aggregation lives in the SQL // service/repository; this controller stays a thin HTTP boundary. [HttpGet("home")] public async Task GetHome(CancellationToken ct = default) { var result = await _sqlTrackService.GetHomeStats(ct); if (!result.Success || result.Value is null) { var error = result.Messages.FirstOrDefault()?.Message ?? "Unknown error"; _logger.LogError("GetHome stats failed: {Error}", error); return StatusCode(500, "Failed to load stats"); } return Ok(result.Value); } }