Initial import into Gitea
This commit is contained in:
48
IntelligenceApi/Controllers/DemographicsController.cs
Normal file
48
IntelligenceApi/Controllers/DemographicsController.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using IntelligenceApi.Engines;
|
||||
using IntelligenceApi.Models;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace IntelligenceApi.Controllers;
|
||||
|
||||
/// <summary>
|
||||
/// Demographics analysis endpoint.
|
||||
///
|
||||
/// Called exclusively by the Gateway's IntelligenceApiClient after it fetches
|
||||
/// raw census data from the database. This container derives audience
|
||||
/// recommendations from the raw data — age chips, income tiers, insights.
|
||||
///
|
||||
/// POST /api/demographics/analyze
|
||||
/// </summary>
|
||||
[ApiController]
|
||||
[Route("api/demographics")]
|
||||
public sealed class DemographicsController : ControllerBase
|
||||
{
|
||||
private readonly DemographicsAnalyzer _analyzer;
|
||||
private readonly ILogger<DemographicsController> _log;
|
||||
|
||||
public DemographicsController(DemographicsAnalyzer analyzer, ILogger<DemographicsController> log)
|
||||
{
|
||||
_analyzer = analyzer;
|
||||
_log = log;
|
||||
}
|
||||
|
||||
[HttpPost("analyze")]
|
||||
public IActionResult Analyze([FromBody] DemographicAnalysisRequest? request)
|
||||
{
|
||||
if (request == null || string.IsNullOrWhiteSpace(request.Zcta))
|
||||
return BadRequest(new { ok = false, error = "zcta and census data are required" });
|
||||
|
||||
_log.LogInformation("[Demographics] Analyze | ZCTA={Zcta}", request.Zcta);
|
||||
|
||||
try
|
||||
{
|
||||
var result = _analyzer.Analyze(request);
|
||||
return Ok(result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
_log.LogError(ex, "[Demographics] Analysis error | ZCTA={Zcta}", request.Zcta);
|
||||
return StatusCode(500, new { ok = false, error = "Demographics analysis error" });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user