From eec67a90f0dab2678ccd38bb3d22a91c5a775767 Mon Sep 17 00:00:00 2001 From: SmartRootsSrl Date: Fri, 20 Mar 2026 12:06:30 +0100 Subject: [PATCH] feat: add ShowBranding flag propagation from API to report data Co-Authored-By: Claude Sonnet 4.6 --- .../Controllers/ReportController.cs | 20 +++++++++++-------- .../Models/CertificateModels.cs | 1 + .../Implementations/ReportOrchestrator.cs | 10 ++++++---- .../Services/Interfaces/IServices.cs | 2 +- 4 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CertReports.Syncfusion/Controllers/ReportController.cs b/CertReports.Syncfusion/Controllers/ReportController.cs index 6d702a7..cda6f9a 100644 --- a/CertReports.Syncfusion/Controllers/ReportController.cs +++ b/CertReports.Syncfusion/Controllers/ReportController.cs @@ -42,7 +42,8 @@ public class ReportController : ControllerBase [HttpGet] public async Task 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); } /// @@ -77,14 +78,16 @@ public class ReportController : ControllerBase /// In produzione proteggere con autenticazione. /// [HttpGet("by-isin/{isin}")] - public async Task GenerateReportByIsin(string isin) + public async Task 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); } /// @@ -93,7 +96,8 @@ public class ReportController : ControllerBase [HttpGet("download")] public async Task 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 GenerateAndReturnPdf(string isin) + private async Task 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"); diff --git a/CertReports.Syncfusion/Models/CertificateModels.cs b/CertReports.Syncfusion/Models/CertificateModels.cs index c311bee..879cc27 100644 --- a/CertReports.Syncfusion/Models/CertificateModels.cs +++ b/CertReports.Syncfusion/Models/CertificateModels.cs @@ -155,4 +155,5 @@ public class CertificateReportData public List Eventi { get; set; } = new(); public ScenarioAnalysis Scenario { get; set; } = new(); public byte[]? ChartImage { get; set; } + public bool ShowBranding { get; set; } = false; } diff --git a/CertReports.Syncfusion/Services/Implementations/ReportOrchestrator.cs b/CertReports.Syncfusion/Services/Implementations/ReportOrchestrator.cs index 06b38d0..38b638b 100644 --- a/CertReports.Syncfusion/Services/Implementations/ReportOrchestrator.cs +++ b/CertReports.Syncfusion/Services/Implementations/ReportOrchestrator.cs @@ -38,10 +38,11 @@ public class ReportOrchestrator : IReportOrchestrator _logger = logger; } - public async Task GenerateReportAsync(string isin) + public async Task 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) diff --git a/CertReports.Syncfusion/Services/Interfaces/IServices.cs b/CertReports.Syncfusion/Services/Interfaces/IServices.cs index cd16c8e..4b9028d 100644 --- a/CertReports.Syncfusion/Services/Interfaces/IServices.cs +++ b/CertReports.Syncfusion/Services/Interfaces/IServices.cs @@ -46,5 +46,5 @@ public interface IPdfMergerService /// public interface IReportOrchestrator { - Task GenerateReportAsync(string isin); + Task GenerateReportAsync(string isin, bool showBranding = false); }