feat: add ShowBranding flag propagation from API to report data

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-20 12:06:30 +01:00
parent 85ee66750a
commit eec67a90f0
4 changed files with 20 additions and 13 deletions

View File

@@ -42,7 +42,8 @@ public class ReportController : ControllerBase
[HttpGet]
public async Task<IActionResult> GenerateReport(
[FromQuery(Name = "p")] string? encryptedIsin = null,
[FromQuery(Name = "alias")] string? aliasId = null)
[FromQuery(Name = "alias")] string? aliasId = null,
[FromQuery(Name = "branding")] bool showBranding = false)
{
string? isin = null;
@@ -69,7 +70,7 @@ public class ReportController : ControllerBase
return BadRequest("Specificare il parametro 'p' (ISIN cifrato) o 'alias' (alias ID).");
}
return await GenerateAndReturnPdf(isin);
return await GenerateAndReturnPdf(isin, showBranding);
}
/// <summary>
@@ -77,14 +78,16 @@ public class ReportController : ControllerBase
/// In produzione proteggere con autenticazione.
/// </summary>
[HttpGet("by-isin/{isin}")]
public async Task<IActionResult> GenerateReportByIsin(string isin)
public async Task<IActionResult> GenerateReportByIsin(
string isin,
[FromQuery(Name = "branding")] bool showBranding = false)
{
if (string.IsNullOrWhiteSpace(isin) || isin.Length < 12)
{
return BadRequest("ISIN non valido.");
}
return await GenerateAndReturnPdf(isin);
return await GenerateAndReturnPdf(isin, showBranding);
}
/// <summary>
@@ -93,7 +96,8 @@ public class ReportController : ControllerBase
[HttpGet("download")]
public async Task<IActionResult> DownloadReport(
[FromQuery(Name = "p")] string? encryptedIsin = null,
[FromQuery(Name = "alias")] string? aliasId = null)
[FromQuery(Name = "alias")] string? aliasId = null,
[FromQuery(Name = "branding")] bool showBranding = false)
{
string? isin = null;
@@ -107,7 +111,7 @@ public class ReportController : ControllerBase
try
{
var pdfBytes = await _orchestrator.GenerateReportAsync(isin);
var pdfBytes = await _orchestrator.GenerateReportAsync(isin, showBranding);
return File(pdfBytes, "application/pdf", $"{isin}.pdf");
}
catch (Exception ex)
@@ -119,12 +123,12 @@ public class ReportController : ControllerBase
// ─── Helper ────────────────────────────────────────────────────────
private async Task<IActionResult> GenerateAndReturnPdf(string isin)
private async Task<IActionResult> GenerateAndReturnPdf(string isin, bool showBranding)
{
try
{
_logger.LogInformation("Richiesta report per ISIN {Isin}", isin);
var pdfBytes = await _orchestrator.GenerateReportAsync(isin);
var pdfBytes = await _orchestrator.GenerateReportAsync(isin, showBranding);
// Inline: il PDF si apre direttamente nel browser
Response.Headers.Append("Content-Disposition", $"inline; filename={isin}.pdf");

View File

@@ -155,4 +155,5 @@ public class CertificateReportData
public List<CertificateEvent> Eventi { get; set; } = new();
public ScenarioAnalysis Scenario { get; set; } = new();
public byte[]? ChartImage { get; set; }
public bool ShowBranding { get; set; } = false;
}

View File

@@ -38,10 +38,11 @@ public class ReportOrchestrator : IReportOrchestrator
_logger = logger;
}
public async Task<byte[]> GenerateReportAsync(string isin)
public async Task<byte[]> GenerateReportAsync(string isin, bool showBranding = false)
{
// ── Cache check ──────────────────────────────────────────────────
var cached = _cache.Get(isin);
// ── Cache check (chiave include branding) ─────────────────────────
var cacheKey = showBranding ? $"{isin}:branded" : isin;
var cached = _cache.Get(cacheKey);
if (cached != null)
{
_logger.LogInformation("Report per ISIN {Isin} servito da cache ({Size} bytes)", isin, cached.Length);
@@ -56,6 +57,7 @@ public class ReportOrchestrator : IReportOrchestrator
Info = await _dataService.GetCertificateInfoAsync(isin),
Eventi = await _dataService.GetCertificateEventsAsync(isin),
Scenario = await _dataService.GetScenarioAnalysisAsync(isin),
ShowBranding = showBranding,
};
// Determina se lo scenario ha dati validi (evita doppia chiamata SP)
@@ -106,7 +108,7 @@ public class ReportOrchestrator : IReportOrchestrator
isin, finalPdf.Length, pdfSections.Count);
// Salva in cache
_cache.Set(isin, finalPdf);
_cache.Set(cacheKey, finalPdf);
// Cleanup
foreach (var doc in pdfSections)

View File

@@ -46,5 +46,5 @@ public interface IPdfMergerService
/// </summary>
public interface IReportOrchestrator
{
Task<byte[]> GenerateReportAsync(string isin);
Task<byte[]> GenerateReportAsync(string isin, bool showBranding = false);
}