Wire NowPlayingStats to live aggregates: add SQL track duration column, stats endpoint, and duration backfill

This commit is contained in:
daniel-c-harvey
2026-06-18 11:53:49 -04:00
parent 8ddecb4acc
commit 5f0422a263
26 changed files with 1089 additions and 9 deletions
@@ -0,0 +1,36 @@
using DeepDrftData;
using Microsoft.AspNetCore.Mvc;
namespace DeepDrftAPI.Controllers;
[ApiController]
[Route("api/[controller]")]
public class StatsController : ControllerBase
{
private readonly ITrackService _sqlTrackService;
private readonly ILogger<StatsController> _logger;
public StatsController(ITrackService sqlTrackService, ILogger<StatsController> 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<ActionResult> 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);
}
}