Skip to content

Commit f6bbab4

Browse files
committed
feat: 591
Merged PR 180: Gestione download INPS Related work items: #591
1 parent 326cb16 commit f6bbab4

File tree

1 file changed

+52
-10
lines changed

1 file changed

+52
-10
lines changed

src/Presentation/PortaleFatture.BE.Api/Modules/SEND/Notifiche/NotificaModule.cs

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
using System.Globalization;
2+
using Azure.Storage.Blobs;
3+
using Azure.Storage;
4+
using Azure.Storage.Sas;
25
using CsvHelper;
36
using MediatR;
47
using Microsoft.AspNetCore.Authorization;
58
using Microsoft.AspNetCore.Cors;
69
using Microsoft.AspNetCore.Http.HttpResults;
710
using Microsoft.AspNetCore.Mvc;
811
using Microsoft.Extensions.Localization;
12+
using Microsoft.Extensions.Options;
913
using PortaleFatture.BE.Api.Infrastructure;
1014
using PortaleFatture.BE.Api.Infrastructure.Documenti;
1115
using PortaleFatture.BE.Api.Modules.SEND.DatiFatturazioni.Payload.Request;
1216
using PortaleFatture.BE.Api.Modules.SEND.Notifiche.Extensions;
1317
using PortaleFatture.BE.Api.Modules.SEND.Notifiche.Payload.Request;
1418
using PortaleFatture.BE.Api.Modules.SEND.Notifiche.Payload.Response;
1519
using PortaleFatture.BE.Core.Auth;
20+
using PortaleFatture.BE.Core.Common;
1621
using PortaleFatture.BE.Core.Entities.SEND.Notifiche;
1722
using PortaleFatture.BE.Core.Extensions;
1823
using PortaleFatture.BE.Core.Resources;
@@ -22,6 +27,7 @@
2227
using PortaleFatture.BE.Infrastructure.Common.SEND.Notifiche.Dto;
2328
using PortaleFatture.BE.Infrastructure.Common.SEND.Notifiche.Queries;
2429
using static Microsoft.AspNetCore.Http.TypedResults;
30+
using PortaleFatture.BE.Infrastructure.Common.SEND.SelfCare.Queries;
2531

2632
namespace PortaleFatture.BE.Api.Modules.Notifiche;
2733

@@ -537,21 +543,57 @@ private async Task<IResult> GetNotificheRicercaDocumentAsync(
537543
[FromBody] NotificheRicercaRequest request,
538544
[FromServices] IStringLocalizer<Localization> localizer,
539545
[FromServices] IMediator handler,
546+
[FromServices] IPortaleFattureOptions options,
540547
[FromQuery] bool? binary = null)
541548
{
542549
var authInfo = context.GetAuthInfo();
543-
var notifiche = await handler.Send(request.Map(authInfo, null, null));
544-
if (notifiche == null || notifiche.Count == 0)
545-
return NotFound();
550+
var tempAnno = 2025;
551+
var tempMese = 1;
552+
var tempIdEnte = "53b40136-65f2-424b-acfb-7fae17e35c60";
553+
var tempName = "inps";
546554

547-
var stream = await notifiche.Notifiche!.ToStream<SimpleNotificaDto, SimpleNotificaEnteDtoMap>();
548-
if (stream.Length == 0)
549-
return NotFound();
555+
if (request.Anno == tempAnno && request.Mese == tempMese && authInfo.IdEnte == tempIdEnte)
556+
{
557+
var ente = await handler.Send(new EnteQueryGetById(authInfo));
558+
if(ente == null) return NotFound();
559+
if(!ente.Descrizione!.ToLower()!.Contains(tempName))
560+
{
561+
return NotFound();
562+
}
563+
564+
var blobNameDetailed = "Notifiche _Istituto Nazionale Previdenza Sociale - INPS_01 _2025.csv";
565+
var storageSharedKeyCredential = new StorageSharedKeyCredential(options.StoragePagoPAFinancial!.AccountName, options.StoragePagoPAFinancial!.AccountKey);
566+
var blobContainerName = "temp";
550567

551-
var filename = $"{Guid.NewGuid()}.csv";
552-
var mimeCsv = "text/csv";
553-
stream.Position = 0;
554-
return Results.Stream(stream, mimeCsv, filename);
568+
BlobSasBuilder sasBuilderDetailed = new()
569+
{
570+
BlobContainerName = blobContainerName,
571+
BlobName = blobNameDetailed,
572+
Resource = "b",
573+
StartsOn = DateTimeOffset.UtcNow.AddMinutes(-5),
574+
ExpiresOn = DateTimeOffset.UtcNow.AddMinutes(30)
575+
};
576+
577+
sasBuilderDetailed.SetPermissions(BlobSasPermissions.Read);
578+
var sasTokenDetailed = sasBuilderDetailed.ToSasQueryParameters(storageSharedKeyCredential).ToString();
579+
var blobUrlDetailed = $"https://{options.StoragePagoPAFinancial!.AccountName}.blob.core.windows.net/{blobContainerName}/{blobNameDetailed}";
580+
return Ok($"{blobUrlDetailed}?{sasTokenDetailed}");
581+
}
582+
else
583+
{
584+
var notifiche = await handler.Send(request.Map(authInfo, null, null));
585+
if (notifiche == null || notifiche.Count == 0)
586+
return NotFound();
587+
588+
var stream = await notifiche.Notifiche!.ToStream<SimpleNotificaDto, SimpleNotificaEnteDtoMap>();
589+
if (stream.Length == 0)
590+
return NotFound();
591+
592+
var filename = $"{Guid.NewGuid()}.csv";
593+
var mimeCsv = "text/csv";
594+
stream.Position = 0;
595+
return Results.Stream(stream, mimeCsv, filename);
596+
}
555597
}
556598

557599
[Authorize(Roles = $"{Ruolo.ADMIN}", Policy = Module.SelfCarePolicy)]

0 commit comments

Comments
 (0)