25 lines
848 B
C#
25 lines
848 B
C#
using InboxIntel.Application.Abstractions;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
namespace InboxIntel.Api.Controllers;
|
|
|
|
public class ExportController : ApiControllerBase
|
|
{
|
|
private readonly IExportService _export;
|
|
public ExportController(IExportService export) => _export = export;
|
|
|
|
/// <summary>Export an inbox report. format = pdf | csv | json.</summary>
|
|
[HttpGet("report")]
|
|
public async Task<IActionResult> Report([FromQuery] string format = "pdf", CancellationToken ct = default)
|
|
{
|
|
var fmt = format.ToLowerInvariant() switch
|
|
{
|
|
"csv" => ExportFormat.Csv,
|
|
"json" => ExportFormat.Json,
|
|
_ => ExportFormat.Pdf
|
|
};
|
|
var (content, contentType, fileName) = await _export.ExportReportAsync(UserId, fmt, ct);
|
|
return File(content, contentType, fileName);
|
|
}
|
|
}
|