|
1 | 1 | using System.Globalization; |
| 2 | +using Azure.Storage.Blobs; |
| 3 | +using Azure.Storage; |
| 4 | +using Azure.Storage.Sas; |
2 | 5 | using CsvHelper; |
3 | 6 | using MediatR; |
4 | 7 | using Microsoft.AspNetCore.Authorization; |
5 | 8 | using Microsoft.AspNetCore.Cors; |
6 | 9 | using Microsoft.AspNetCore.Http.HttpResults; |
7 | 10 | using Microsoft.AspNetCore.Mvc; |
8 | 11 | using Microsoft.Extensions.Localization; |
| 12 | +using Microsoft.Extensions.Options; |
9 | 13 | using PortaleFatture.BE.Api.Infrastructure; |
10 | 14 | using PortaleFatture.BE.Api.Infrastructure.Documenti; |
11 | 15 | using PortaleFatture.BE.Api.Modules.SEND.DatiFatturazioni.Payload.Request; |
12 | 16 | using PortaleFatture.BE.Api.Modules.SEND.Notifiche.Extensions; |
13 | 17 | using PortaleFatture.BE.Api.Modules.SEND.Notifiche.Payload.Request; |
14 | 18 | using PortaleFatture.BE.Api.Modules.SEND.Notifiche.Payload.Response; |
15 | 19 | using PortaleFatture.BE.Core.Auth; |
| 20 | +using PortaleFatture.BE.Core.Common; |
16 | 21 | using PortaleFatture.BE.Core.Entities.SEND.Notifiche; |
17 | 22 | using PortaleFatture.BE.Core.Extensions; |
18 | 23 | using PortaleFatture.BE.Core.Resources; |
|
22 | 27 | using PortaleFatture.BE.Infrastructure.Common.SEND.Notifiche.Dto; |
23 | 28 | using PortaleFatture.BE.Infrastructure.Common.SEND.Notifiche.Queries; |
24 | 29 | using static Microsoft.AspNetCore.Http.TypedResults; |
| 30 | +using PortaleFatture.BE.Infrastructure.Common.SEND.SelfCare.Queries; |
25 | 31 |
|
26 | 32 | namespace PortaleFatture.BE.Api.Modules.Notifiche; |
27 | 33 |
|
@@ -537,21 +543,57 @@ private async Task<IResult> GetNotificheRicercaDocumentAsync( |
537 | 543 | [FromBody] NotificheRicercaRequest request, |
538 | 544 | [FromServices] IStringLocalizer<Localization> localizer, |
539 | 545 | [FromServices] IMediator handler, |
| 546 | + [FromServices] IPortaleFattureOptions options, |
540 | 547 | [FromQuery] bool? binary = null) |
541 | 548 | { |
542 | 549 | 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"; |
546 | 554 |
|
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"; |
550 | 567 |
|
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 | + } |
555 | 597 | } |
556 | 598 |
|
557 | 599 | [Authorize(Roles = $"{Ruolo.ADMIN}", Policy = Module.SelfCarePolicy)] |
|
0 commit comments