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:
@@ -42,7 +42,8 @@ public class ReportController : ControllerBase
|
|||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<IActionResult> GenerateReport(
|
public async Task<IActionResult> GenerateReport(
|
||||||
[FromQuery(Name = "p")] string? encryptedIsin = null,
|
[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;
|
string? isin = null;
|
||||||
|
|
||||||
@@ -69,7 +70,7 @@ public class ReportController : ControllerBase
|
|||||||
return BadRequest("Specificare il parametro 'p' (ISIN cifrato) o 'alias' (alias ID).");
|
return BadRequest("Specificare il parametro 'p' (ISIN cifrato) o 'alias' (alias ID).");
|
||||||
}
|
}
|
||||||
|
|
||||||
return await GenerateAndReturnPdf(isin);
|
return await GenerateAndReturnPdf(isin, showBranding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -77,14 +78,16 @@ public class ReportController : ControllerBase
|
|||||||
/// In produzione proteggere con autenticazione.
|
/// In produzione proteggere con autenticazione.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[HttpGet("by-isin/{isin}")]
|
[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)
|
if (string.IsNullOrWhiteSpace(isin) || isin.Length < 12)
|
||||||
{
|
{
|
||||||
return BadRequest("ISIN non valido.");
|
return BadRequest("ISIN non valido.");
|
||||||
}
|
}
|
||||||
|
|
||||||
return await GenerateAndReturnPdf(isin);
|
return await GenerateAndReturnPdf(isin, showBranding);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -93,7 +96,8 @@ public class ReportController : ControllerBase
|
|||||||
[HttpGet("download")]
|
[HttpGet("download")]
|
||||||
public async Task<IActionResult> DownloadReport(
|
public async Task<IActionResult> DownloadReport(
|
||||||
[FromQuery(Name = "p")] string? encryptedIsin = null,
|
[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;
|
string? isin = null;
|
||||||
|
|
||||||
@@ -107,7 +111,7 @@ public class ReportController : ControllerBase
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var pdfBytes = await _orchestrator.GenerateReportAsync(isin);
|
var pdfBytes = await _orchestrator.GenerateReportAsync(isin, showBranding);
|
||||||
return File(pdfBytes, "application/pdf", $"{isin}.pdf");
|
return File(pdfBytes, "application/pdf", $"{isin}.pdf");
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
@@ -119,12 +123,12 @@ public class ReportController : ControllerBase
|
|||||||
|
|
||||||
// ─── Helper ────────────────────────────────────────────────────────
|
// ─── Helper ────────────────────────────────────────────────────────
|
||||||
|
|
||||||
private async Task<IActionResult> GenerateAndReturnPdf(string isin)
|
private async Task<IActionResult> GenerateAndReturnPdf(string isin, bool showBranding)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Richiesta report per ISIN {Isin}", isin);
|
_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
|
// Inline: il PDF si apre direttamente nel browser
|
||||||
Response.Headers.Append("Content-Disposition", $"inline; filename={isin}.pdf");
|
Response.Headers.Append("Content-Disposition", $"inline; filename={isin}.pdf");
|
||||||
|
|||||||
@@ -155,4 +155,5 @@ public class CertificateReportData
|
|||||||
public List<CertificateEvent> Eventi { get; set; } = new();
|
public List<CertificateEvent> Eventi { get; set; } = new();
|
||||||
public ScenarioAnalysis Scenario { get; set; } = new();
|
public ScenarioAnalysis Scenario { get; set; } = new();
|
||||||
public byte[]? ChartImage { get; set; }
|
public byte[]? ChartImage { get; set; }
|
||||||
|
public bool ShowBranding { get; set; } = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,10 +38,11 @@ public class ReportOrchestrator : IReportOrchestrator
|
|||||||
_logger = logger;
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task<byte[]> GenerateReportAsync(string isin)
|
public async Task<byte[]> GenerateReportAsync(string isin, bool showBranding = false)
|
||||||
{
|
{
|
||||||
// ── Cache check ──────────────────────────────────────────────────
|
// ── Cache check (chiave include branding) ─────────────────────────
|
||||||
var cached = _cache.Get(isin);
|
var cacheKey = showBranding ? $"{isin}:branded" : isin;
|
||||||
|
var cached = _cache.Get(cacheKey);
|
||||||
if (cached != null)
|
if (cached != null)
|
||||||
{
|
{
|
||||||
_logger.LogInformation("Report per ISIN {Isin} servito da cache ({Size} bytes)", isin, cached.Length);
|
_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),
|
Info = await _dataService.GetCertificateInfoAsync(isin),
|
||||||
Eventi = await _dataService.GetCertificateEventsAsync(isin),
|
Eventi = await _dataService.GetCertificateEventsAsync(isin),
|
||||||
Scenario = await _dataService.GetScenarioAnalysisAsync(isin),
|
Scenario = await _dataService.GetScenarioAnalysisAsync(isin),
|
||||||
|
ShowBranding = showBranding,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Determina se lo scenario ha dati validi (evita doppia chiamata SP)
|
// Determina se lo scenario ha dati validi (evita doppia chiamata SP)
|
||||||
@@ -106,7 +108,7 @@ public class ReportOrchestrator : IReportOrchestrator
|
|||||||
isin, finalPdf.Length, pdfSections.Count);
|
isin, finalPdf.Length, pdfSections.Count);
|
||||||
|
|
||||||
// Salva in cache
|
// Salva in cache
|
||||||
_cache.Set(isin, finalPdf);
|
_cache.Set(cacheKey, finalPdf);
|
||||||
|
|
||||||
// Cleanup
|
// Cleanup
|
||||||
foreach (var doc in pdfSections)
|
foreach (var doc in pdfSections)
|
||||||
|
|||||||
@@ -46,5 +46,5 @@ public interface IPdfMergerService
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IReportOrchestrator
|
public interface IReportOrchestrator
|
||||||
{
|
{
|
||||||
Task<byte[]> GenerateReportAsync(string isin);
|
Task<byte[]> GenerateReportAsync(string isin, bool showBranding = false);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user