68 lines
2.8 KiB
C#
68 lines
2.8 KiB
C#
using Management.Data;
|
|
using Management.Security;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using System.Text.Json;
|
|
|
|
namespace Management.Controllers.Admin;
|
|
|
|
/// <summary>
|
|
/// Admin endpoints for campaign performance reporting and intelligence.
|
|
/// Provides normalized metrics across all providers (Google, Meta, TikTok).
|
|
/// Requires Admin role.
|
|
///
|
|
/// ENDPOINTS:
|
|
/// POST /api/admin/reporting/summary - KPI summary across all campaigns
|
|
/// POST /api/admin/reporting/campaigns - Per-campaign performance metrics
|
|
/// GET /api/admin/reporting/campaigns/{id} - Detailed metrics for one initiative
|
|
/// POST /api/admin/reporting/insights - Optimization recommendations
|
|
/// POST /api/admin/reporting/analysis - Post-campaign analysis data
|
|
/// </summary>
|
|
[ApiController]
|
|
[Route("api/admin/reporting")]
|
|
public sealed class AdminReportingController : AdminControllerBase
|
|
{
|
|
public AdminReportingController(SqlService sql, ClientContext client, ILogger<AdminReportingController> log)
|
|
: base(sql, client, log) { }
|
|
|
|
/// <summary>
|
|
/// KPI summary: totals for spend, impressions, clicks, conversions, CTR, CPC, ROAS.
|
|
/// Body: { dateFrom?, dateTo?, clientId? }
|
|
/// </summary>
|
|
[HttpPost("summary")]
|
|
public Task<IActionResult> Summary([FromBody] JsonElement body, CancellationToken ct)
|
|
=> CallProc("spAdminReporting", "summary", body.ToString(), ct);
|
|
|
|
/// <summary>
|
|
/// Per-campaign performance list with channel breakdowns.
|
|
/// Body: { status?, clientId?, dateFrom?, dateTo?, sortBy?, sortDir?, page?, pageSize? }
|
|
/// </summary>
|
|
[HttpPost("campaigns")]
|
|
public Task<IActionResult> Campaigns([FromBody] JsonElement body, CancellationToken ct)
|
|
=> CallProc("spAdminReporting", "campaigns", body.ToString(), ct);
|
|
|
|
/// <summary>
|
|
/// Detailed metrics for a single initiative with daily time-series
|
|
/// and per-channel breakdowns.
|
|
/// </summary>
|
|
[HttpGet("campaigns/{initiativeId:long}")]
|
|
public Task<IActionResult> CampaignDetail(long initiativeId, CancellationToken ct)
|
|
=> CallProc("spAdminReporting", "detail", new { initiativeId }, ct);
|
|
|
|
/// <summary>
|
|
/// Optimization insights and recommendations.
|
|
/// Body: { severity?, clientId? }
|
|
/// </summary>
|
|
[HttpPost("insights")]
|
|
public Task<IActionResult> Insights([FromBody] JsonElement body, CancellationToken ct)
|
|
=> CallProc("spAdminReporting", "insights", body.ToString(), ct);
|
|
|
|
/// <summary>
|
|
/// Post-campaign analysis: completed campaigns with ROI, cost-efficiency,
|
|
/// and channel-level performance comparisons.
|
|
/// Body: { clientId?, dateFrom?, dateTo? }
|
|
/// </summary>
|
|
[HttpPost("analysis")]
|
|
public Task<IActionResult> Analysis([FromBody] JsonElement body, CancellationToken ct)
|
|
=> CallProc("spAdminReporting", "analysis", body.ToString(), ct);
|
|
}
|