- Modificado `InvoiceIngestionService` para usar `IServiceScopeFactory`, permitindo melhor gerenciamento do ciclo de vida de dependências. - Atualizações de pacotes em diversos projetos (`ComplianceNFs.Core`, `ComplianceNFs.Infrastructure`, `ComplianceNFs.Service`, `ComplianceNFs.Monitor`, `ComplianceNFs.Infrastructure.Tests`). - Alterado namespace de `AuditComplianceNFsTest.cs` para `ComplianceNFs.Infrastructure.Tests`. - Refatorações no `AttachmentRepository` e `ComplianceNFsDbContext` para simplificar código e melhorar legibilidade. - Atualizado teste `InvoiceIngestionServiceTests` para refletir mudanças no uso de escopos de serviço. - Melhorias gerais na arquitetura e alinhamento com boas práticas.
52 lines
2.0 KiB
C#
52 lines
2.0 KiB
C#
using System;
|
|
using System.Threading.Tasks;
|
|
using ComplianceNFs.Core.Entities;
|
|
using ComplianceNFs.Core.Ports;
|
|
using Npgsql;
|
|
using Newtonsoft.Json;
|
|
using System.Numerics;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace ComplianceNFs.Infrastructure.Repositories
|
|
{
|
|
public class AttachmentRepository(ComplianceNFsDbContext dbContext, ILogger<AttachmentRepository> logger) : IAttachmentRepository
|
|
{
|
|
private readonly ComplianceNFsDbContext _dbContext = dbContext;
|
|
private readonly ILogger<AttachmentRepository> _logger = logger;
|
|
|
|
public async Task SaveRawAsync(EnergyInvoice invoice)
|
|
{
|
|
try
|
|
{
|
|
await _dbContext.EnergyInvoices.AddAsync(invoice);
|
|
await _dbContext.SaveChangesAsync();
|
|
_logger.LogInformation("Saved raw invoice {InvoiceId} to EnergyInvoices table.", invoice.InvoiceId);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error saving raw invoice {InvoiceId} to EnergyInvoices table.", invoice.InvoiceId);
|
|
throw;
|
|
}
|
|
}
|
|
|
|
public async Task UpdateMatchAsync(int invoiceId, BigInteger matchedCodTE, InvoiceStatus status, string notes)
|
|
{
|
|
try
|
|
{
|
|
var invoice = await _dbContext.EnergyInvoices.FirstOrDefaultAsync(e => e.InvoiceId == invoiceId) ?? throw new InvalidOperationException($"Invoice with ID {invoiceId} not found.");
|
|
invoice.MatchedCodTE = matchedCodTE;
|
|
invoice.Status = status;
|
|
invoice.DiscrepancyNotes = notes;
|
|
await _dbContext.SaveChangesAsync();
|
|
_logger.LogInformation("Updated match for invoice {InvoiceId}.", invoiceId);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_logger.LogError(ex, "Error updating match for invoice {InvoiceId}.", invoiceId);
|
|
throw;
|
|
}
|
|
}
|
|
}
|
|
}
|