Skip to content

Commit

Permalink
Codice SDI
Browse files Browse the repository at this point in the history
Related work items: #484
  • Loading branch information
mg-dgsspa committed Dec 5, 2024
1 parent 042d317 commit 30223f8
Show file tree
Hide file tree
Showing 52 changed files with 1,041 additions and 107 deletions.
7 changes: 7 additions & 0 deletions PortaleFatture.BE.Api.sln
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PortaleFatture.BE.EmailSend
EndProject
Project("{888888A0-9F3D-457C-B088-3A5042F75D52}") = "PortaleFatture.BE.ImportFinancepagoPA", "src\Presentation\PortaleFatture.BE.ImportFinancepagoPA\PortaleFatture.BE.ImportFinancepagoPA.pyproj", "{58D379F3-5E9D-4C83-B4DA-7690318A2BD1}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortaleFatture.BE.SelfCareOnBoardingAPI", "src\Presentation\PortaleFatture.BE.SelfCareOnBoardingAPI\PortaleFatture.BE.SelfCareOnBoardingAPI.csproj", "{E32705A0-D6F3-40F7-B2D0-4A08FEAE18B2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -73,6 +75,10 @@ Global
{8D455F55-BD96-4385-AA34-0F7EEFCFC106}.Release|Any CPU.Build.0 = Release|Any CPU
{58D379F3-5E9D-4C83-B4DA-7690318A2BD1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{58D379F3-5E9D-4C83-B4DA-7690318A2BD1}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E32705A0-D6F3-40F7-B2D0-4A08FEAE18B2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E32705A0-D6F3-40F7-B2D0-4A08FEAE18B2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E32705A0-D6F3-40F7-B2D0-4A08FEAE18B2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E32705A0-D6F3-40F7-B2D0-4A08FEAE18B2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -87,6 +93,7 @@ Global
{C57A92B5-0A9B-43EB-807F-D35F46977F65} = {FCE0D4DD-5884-4A2A-814E-F58B18092F76}
{8D455F55-BD96-4385-AA34-0F7EEFCFC106} = {FCE0D4DD-5884-4A2A-814E-F58B18092F76}
{58D379F3-5E9D-4C83-B4DA-7690318A2BD1} = {FCE0D4DD-5884-4A2A-814E-F58B18092F76}
{E32705A0-D6F3-40F7-B2D0-4A08FEAE18B2} = {FCE0D4DD-5884-4A2A-814E-F58B18092F76}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E21864C8-BAF8-4D8B-957E-726DB3040371}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,7 @@ public interface IPortaleFattureOptions
public Storage? Storage { get; set; }
public StorageDocumenti? StorageDocumenti { get; set; }
public Synapse? Synapse { get; set; }
public StoragePagoPAFinancial? StoragePagoPAFinancial { get; set; }
public SelfCareOnBoarding? SelfCareOnBoarding { get; set; }
public StoragePagoPAFinancial? StoragePagoPAFinancial { get; set; }
public SupportAPIService? SupportAPIService { get; set; }
}
18 changes: 17 additions & 1 deletion src/Core/PortaleFatture.BE.Core/Common/PortaleFattureOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,23 @@ public sealed class PortaleFattureOptions : IPortaleFattureOptions
public Storage? Storage { get; set; }
public StorageDocumenti? StorageDocumenti { get; set; }
public Synapse? Synapse { get; set; }
public StoragePagoPAFinancial? StoragePagoPAFinancial { get; set; }
public StoragePagoPAFinancial? StoragePagoPAFinancial { get; set; }
public SelfCareOnBoarding? SelfCareOnBoarding { get; set; }
public SupportAPIService? SupportAPIService { get; set; }
}

public class SupportAPIService()
{
public string? Endpoint { get; set; }
public string? RecipientCodeUri { get; set; }
public string? AuthToken { get; set; }
}

public class SelfCareOnBoarding()
{
public string? Endpoint { get; set; }
public string? RecipientCodeUri{ get; set; }
public string? AuthToken { get; set; }
}

public class Synapse()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class DatiFatturazione
public string? Pec { get; set; }
public bool NotaLegale { get; set; }
public DateTimeOffset DataCreazione { get; set; }
public DateTimeOffset? DataModifica { get; set; }
public IEnumerable<DatiFatturazioneContatto>? Contatti { get; set; }
}
public DateTimeOffset? DataModifica { get; set; }
public IEnumerable<DatiFatturazioneContatto>? Contatti { get; set; }
public string? CodiceSDI { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@
namespace PortaleFatture.BE.Core.Entities.SEND.SelfCare.Dto;

public class EnteContrattoDto
{

[Column("IdEnte")]
{
public string? IdEnte { get; set; }

[Column("RagioneSociale")]

public string? RagioneSociale { get; set; }

[Column("TipoContratto")]

public string? TipoContratto { get; set; }

[Column("IdContratto")]

public string? IdContratto { get; set; }
}

public string? Prodotto { get; set; }

public string? CodiceIPA { get; set; }

public string? CodiceSDI { get; set; }

public string? InstitutionType { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ public class Ente
[Column("istatCode")]
public string? CodiceIstat { get; set; }

[Column("originId")]
public string? CodiceIPA { get; set; }

[Column("city")]
public string? Citta { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ public static string AddJoin(this string sql, string schema)

public static string Add(this string sql, string schema)
{
if (!schema.Contains("."))
schema = $"{schema}.";
return sql.Replace("[schema]", schema);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,35 @@
using MediatR;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using PortaleFatture.BE.Core.Common;
using PortaleFatture.BE.Core.Entities.SEND.DatiFatturazioni;
using PortaleFatture.BE.Core.Entities.Storici;
using PortaleFatture.BE.Core.Exceptions;
using PortaleFatture.BE.Core.Extensions;
using PortaleFatture.BE.Core.Resources;
using PortaleFatture.BE.Infrastructure.Common.Persistence.Schemas;
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiFatturazioni;
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiFatturazioni.Commands;
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiFatturazioni.Commands.Persistence;
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiFatturazioni.Queries.Persistence;
using PortaleFatture.BE.Infrastructure.Common.SEND.SelfCare.Queries.Persistence;
using PortaleFatture.BE.Infrastructure.Common.Storici.Commands;
using PortaleFatture.BE.Infrastructure.Common.Storici.Commands.Persistence;
using PortaleFatture.BE.Infrastructure.Gateway;

namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiFatturazioni.CommandHandlers;

public class DatiFatturazioneCreateCommandHandler : IRequestHandler<DatiFatturazioneCreateCommand, DatiFatturazione>
public class DatiFatturazioneCreateCommandHandler(
IFattureDbContextFactory factory,
ISelfCareOnBoardingHttpClient onBoardingHttpClient,
ISupportAPIServiceHttpClient supportAPIServiceHttpClient,
IStringLocalizer<Localization> localizer,
ILogger<DatiFatturazioneCreateCommandHandler> logger) : IRequestHandler<DatiFatturazioneCreateCommand, DatiFatturazione>
{
private readonly IFattureDbContextFactory _factory;
private readonly ILogger<DatiFatturazioneCreateCommandHandler> _logger;
private readonly IStringLocalizer<Localization> _localizer;
public DatiFatturazioneCreateCommandHandler(
IFattureDbContextFactory factory,
IStringLocalizer<Localization> localizer,
ILogger<DatiFatturazioneCreateCommandHandler> logger)
{
_factory = factory;
_localizer = localizer;
_logger = logger;
}
private readonly IFattureDbContextFactory _factory = factory;
private readonly ILogger<DatiFatturazioneCreateCommandHandler> _logger = logger;
private readonly IStringLocalizer<Localization> _localizer = localizer;
private readonly ISelfCareOnBoardingHttpClient _onBoardingHttpClient = onBoardingHttpClient;
private readonly ISupportAPIServiceHttpClient _supportAPIServiceHttpClient = supportAPIServiceHttpClient;

public async Task<DatiFatturazione> Handle(DatiFatturazioneCreateCommand command, CancellationToken ct)
{
Expand All @@ -39,12 +39,37 @@ public async Task<DatiFatturazione> Handle(DatiFatturazioneCreateCommand command
if (!string.IsNullOrEmpty(error))
throw new ValidationException(_localizer[error, errorDetails]);

command.DataCreazione = command.DataCreazione == null ? adesso : command.DataCreazione;
command.DataCreazione = command.DataCreazione == null ? adesso : command.DataCreazione;

using var uow = await _factory.Create(true, cancellationToken: ct);
using var uow = await _factory.Create(true, cancellationToken: ct);
var actualValue = await uow.Query(new DatiFatturazioneQueryGetByIdEntePersistence(command.AuthenticationInfo.IdEnte!), ct);
if (actualValue != null)
throw new DomainException(_localizer["DatiFatturazioneIdEnteExistent", command.AuthenticationInfo.IdEnte!]);

if (String.IsNullOrEmpty(command.CodiceSDI))
throw new ValidationException("Attenzione, devi validare il codice SDI"); //non puoi cancellare il codice SDI

if (!String.IsNullOrEmpty(command.CodiceSDI))
{
var ente = await uow.Query(new EnteCodiceSDIQueryGetByIdPersistence(command.AuthenticationInfo.IdEnte), ct);
var (okValidation, msgValidation) = await _onBoardingHttpClient.RecipientCodeVerification(
ente,
command.CodiceSDI,
ct);

if (okValidation)
{
var (oKUpdate, msgUpdate) = await _supportAPIServiceHttpClient.UpdateRecipientCode(
ente,
command.CodiceSDI,
ct);
if (!oKUpdate)
throw new ValidationException(msgUpdate);
}
else
throw new ValidationException(msgValidation);
}

try
{
var rowAffected = 0;
Expand All @@ -68,6 +93,7 @@ public async Task<DatiFatturazione> Handle(DatiFatturazioneCreateCommand command
throw new DomainException(_localizer["DatiFatturazioneInputError"]);
}
}

var actualDatiFatturazione = command.Mapper(id.Value);
rowAffected = await uow.Execute(new StoricoCreateCommandPersistence(new StoricoCreateCommand(
command.AuthenticationInfo,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using MediatR;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Logging;
using PortaleFatture.BE.Core.Common;
using PortaleFatture.BE.Core.Entities.SEND.DatiFatturazioni;
using PortaleFatture.BE.Core.Entities.Storici;
using PortaleFatture.BE.Core.Exceptions;
Expand All @@ -10,26 +11,25 @@
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiFatturazioni.Commands;
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiFatturazioni.Commands.Persistence;
using PortaleFatture.BE.Infrastructure.Common.SEND.DatiFatturazioni.Queries.Persistence;
using PortaleFatture.BE.Infrastructure.Common.SEND.SelfCare.Queries.Persistence;
using PortaleFatture.BE.Infrastructure.Common.Storici.Commands;
using PortaleFatture.BE.Infrastructure.Common.Storici.Commands.Persistence;
using PortaleFatture.BE.Infrastructure.Gateway;

namespace PortaleFatture.BE.Infrastructure.Common.SEND.DatiFatturazioni.CommandHandlers;

public class DatiFatturazioneUpdateCommandHandler : IRequestHandler<DatiFatturazioneUpdateCommand, DatiFatturazione>
public class DatiFatturazioneUpdateCommandHandler(
IFattureDbContextFactory factory,
ISelfCareOnBoardingHttpClient onBoardingHttpClient,
ISupportAPIServiceHttpClient supportAPIServiceHttpClient,
IStringLocalizer<Localization> localizer,
ILogger<DatiFatturazioneUpdateCommandHandler> logger) : IRequestHandler<DatiFatturazioneUpdateCommand, DatiFatturazione>
{
private readonly IFattureDbContextFactory _factory;
private readonly ILogger<DatiFatturazioneUpdateCommandHandler> _logger;
private readonly IStringLocalizer<Localization> _localizer;
public DatiFatturazioneUpdateCommandHandler(
IFattureDbContextFactory factory,
IStringLocalizer<Localization> localizer,
ILogger<DatiFatturazioneUpdateCommandHandler> logger)
{
_factory = factory;
_localizer = localizer;
_logger = logger;
}

private readonly IFattureDbContextFactory _factory = factory;
private readonly ILogger<DatiFatturazioneUpdateCommandHandler> _logger = logger;
private readonly IStringLocalizer<Localization> _localizer = localizer;
private readonly ISelfCareOnBoardingHttpClient _onBoardingHttpClient = onBoardingHttpClient;
private readonly ISupportAPIServiceHttpClient _supportAPIServiceHttpClient = supportAPIServiceHttpClient;
public async Task<DatiFatturazione> Handle(DatiFatturazioneUpdateCommand command, CancellationToken ct)
{
var (_, _, _, adesso) = Time.YearMonthDay();
Expand All @@ -40,12 +40,37 @@ public async Task<DatiFatturazione> Handle(DatiFatturazioneUpdateCommand command

command.DataModifica = command.DataModifica == null ? adesso : command.DataModifica;


using var uow = await _factory.Create(true, cancellationToken: ct);
var actualValue = await uow.Query(new DatiFatturazioneQueryGetByIdPersistence(command.Id!), ct) ?? throw new DomainException(_localizer["DatiFatturazioneIdExistent", command.Id!]);

//verifico coerenza dati
if (actualValue.IdEnte != command.AuthenticationInfo.IdEnte || actualValue.Prodotto != command.AuthenticationInfo.Prodotto)
throw new DomainException(_localizer["DatiFatturazioneMismatchError"]);
throw new DomainException(_localizer["DatiFatturazioneMismatchError"]);

if (String.IsNullOrEmpty(command.CodiceSDI))
throw new ValidationException("Attenzione, devi validare il codice SDI"); //non puoi cancellare il codice SDI

else if (!String.IsNullOrEmpty(command.CodiceSDI) && command.CodiceSDI != actualValue.CodiceSDI) // se sono diversi allora rieseguo la validazione via API
{
var ente = await uow.Query(new EnteCodiceSDIQueryGetByIdPersistence(actualValue.IdEnte), ct);
var (okValidation, msgValidation) = await _onBoardingHttpClient.RecipientCodeVerification(
ente,
command.CodiceSDI,
ct);

if(okValidation)
{
var (oKUpdate, msgUpdate) = await _supportAPIServiceHttpClient.UpdateRecipientCode(
ente,
command.CodiceSDI,
ct);
if (!oKUpdate)
throw new ValidationException(msgUpdate);
}
else
throw new ValidationException(msgValidation);
}

try
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public sealed class DatiFatturazioneCreateCommand(IAuthenticationInfo authentica
public string? Map { get; set; }
public string? TipoCommessa { get; set; }
public string? Pec { get; set; }
public DateTime? DataCreazione { get; set; }
public List<DatiFatturazioneContattoCreateCommand>? Contatti { get; set; }
public DateTime? DataCreazione { get; set; }
public List<DatiFatturazioneContattoCreateCommand>? Contatti { get; set; }
public string? CodiceSDI { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,6 @@ public sealed class DatiFatturazioneUpdateCommand(IAuthenticationInfo authentica
public string? TipoCommessa { get; set; }
public string? Pec { get; set; }
public DateTime? DataModifica { get; set; }
public List<DatiFatturazioneContattoCreateCommand>? Contatti { get; set; }
public List<DatiFatturazioneContattoCreateCommand>? Contatti { get; set; }
public string? CodiceSDI { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ INSERT INTO [schema]DatiFatturazione
[map],
fktipocommessa,
pec,
fkprodotto)
fkprodotto,
codiceSDI)
VALUES (@cup,
@notaLegale,
@codcommessa,
Expand All @@ -33,7 +34,8 @@ INSERT INTO [schema]DatiFatturazione
@map,
@tipocommessa,
@pec,
@prodotto);
@prodotto,
@codiceSDI);
Select SCOPE_IDENTITY() 'SCOPE_IDENTITY'";
public async Task<long?> Execute(IDbConnection? connection, string schema, IDbTransaction? transaction, CancellationToken cancellationToken = default)
=> await ((IDatabase)this).ExecuteAsync<long?>(connection!, _sqlInsert.Add(schema), new
Expand All @@ -49,6 +51,7 @@ INSERT INTO [schema]DatiFatturazione
map = _command.Map,
tipoCommessa = _command.TipoCommessa,
pec = _command.Pec,
prodotto = _command.AuthenticationInfo.Prodotto
prodotto = _command.AuthenticationInfo.Prodotto,
codiceSDI = _command.CodiceSDI,
}, transaction);
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ UPDATE [schema]DatiFatturazione
datamodifica = @datamodifica,
[map] = @map,
fktipocommessa = @tipocommessa,
pec = @pec
pec = @pec,
codiceSDI = @codiceSDI
WHERE IdDatiFatturazione = @id;";

private static readonly string _sqlSelect = DatiFatturazioneSQLBuilder.SelectById();
Expand All @@ -42,7 +43,8 @@ UPDATE [schema]DatiFatturazione
map = _command.Map,
tipoCommessa = _command.TipoCommessa,
pec = _command.Pec,
dataModifica = _command.DataModifica
dataModifica = _command.DataModifica,
codiceSDI = _command.CodiceSDI
}, transaction);

if (rowAffected == 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static DatiFatturazione Mapper(this DatiFatturazioneCreateCommand model,
TipoCommessa = model.TipoCommessa,
Contatti = model.Contatti!.Mapper(),
IdEnte = model.AuthenticationInfo.IdEnte,
Prodotto = model.AuthenticationInfo.Prodotto
Prodotto = model.AuthenticationInfo.Prodotto,
CodiceSDI = model.CodiceSDI,
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private static SqlBuilder CreateSelect()
builder.Select(nameof(@obj.Pec));
builder.Select(nameof(@obj.DataCreazione));
builder.Select(nameof(@obj.DataModifica));
builder.Select(nameof(@obj.CodiceSDI));
return builder;
}

Expand Down
Loading

0 comments on commit 30223f8

Please sign in to comment.