From 9a2b5a5f91af13c421ae5e6a4652d20a433e9c92 Mon Sep 17 00:00:00 2001 From: dmolinari Date: Fri, 13 Feb 2026 12:01:18 -0300 Subject: [PATCH] Fix: Quita Archivos de DB Unificadas Sobrantes --- .../OperacionesLegacyController.cs | 119 ------------------ Backend/MotoresArgentinosV2.API/Program.cs | 4 - .../Interfaces/IOperacionesLegacyService.cs | 38 ------ .../Data/EldiaDbContext.cs | 85 ------------- .../Services/OperacionesLegacyService.cs | 111 ---------------- 5 files changed, 357 deletions(-) delete mode 100644 Backend/MotoresArgentinosV2.API/Controllers/OperacionesLegacyController.cs delete mode 100644 Backend/MotoresArgentinosV2.Core/Interfaces/IOperacionesLegacyService.cs delete mode 100644 Backend/MotoresArgentinosV2.Infrastructure/Data/EldiaDbContext.cs delete mode 100644 Backend/MotoresArgentinosV2.Infrastructure/Services/OperacionesLegacyService.cs diff --git a/Backend/MotoresArgentinosV2.API/Controllers/OperacionesLegacyController.cs b/Backend/MotoresArgentinosV2.API/Controllers/OperacionesLegacyController.cs deleted file mode 100644 index f0eddce..0000000 --- a/Backend/MotoresArgentinosV2.API/Controllers/OperacionesLegacyController.cs +++ /dev/null @@ -1,119 +0,0 @@ -using Microsoft.AspNetCore.Mvc; -using MotoresArgentinosV2.Core.Entities; -using MotoresArgentinosV2.Core.Interfaces; - -namespace MotoresArgentinosV2.API.Controllers; - -[ApiController] -[Route("api/[controller]")] -public class OperacionesLegacyController : ControllerBase -{ - private readonly IOperacionesLegacyService _operacionesService; - private readonly ILogger _logger; - - public OperacionesLegacyController(IOperacionesLegacyService operacionesService, ILogger logger) - { - _operacionesService = operacionesService; - _logger = logger; - } - - /// - /// Obtiene los medios de pago disponibles - /// - [HttpGet("medios-pago")] - public async Task>> GetMediosDePago() - { - try - { - var medios = await _operacionesService.ObtenerMediosDePagoAsync(); - return Ok(medios); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error al obtener medios de pago"); - return StatusCode(500, "Ocurrió un error interno al obtener medios de pago"); - } - } - - /// - /// Busca una operación por su número de operación - /// - [HttpGet("{noperacion}")] - public async Task>> GetOperacion(string noperacion) - { - try - { - var operaciones = await _operacionesService.ObtenerOperacionesPorNumeroAsync(noperacion); - - if (operaciones == null || !operaciones.Any()) - { - return NotFound($"No se encontraron operaciones con el número {noperacion}"); - } - - return Ok(operaciones); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error al obtener operación {Noperacion}", noperacion); - return StatusCode(500, "Ocurrió un error interno al buscar la operación"); - } - } - - /// - /// Obtiene operaciones realizadas en un rango de fechas - /// - [HttpGet("buscar")] - public async Task>> GetOperacionesPorFecha([FromQuery] DateTime fechaInicio, [FromQuery] DateTime fechaFin) - { - try - { - if (fechaInicio > fechaFin) - { - return BadRequest("La fecha de inicio no puede ser mayor a la fecha de fin."); - } - - var operaciones = await _operacionesService.ObtenerOperacionesPorFechasAsync(fechaInicio, fechaFin); - return Ok(operaciones); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error al buscar operaciones por fecha"); - return StatusCode(500, "Ocurrió un error interno al buscar operaciones."); - } - } - - /// - /// Registra una nueva operación de pago - /// - [HttpPost] - public async Task CrearOperacion([FromBody] Operacion operacion) - { - try - { - if (!ModelState.IsValid) - { - return BadRequest(ModelState); - } - - // Validar campos mínimos necesarios si es necesario - if (string.IsNullOrEmpty(operacion.Noperacion)) - { - return BadRequest("El número de operación es obligatorio."); - } - - var resultado = await _operacionesService.InsertarOperacionAsync(operacion); - - if (resultado) - { - return CreatedAtAction(nameof(GetOperacion), new { noperacion = operacion.Noperacion }, operacion); - } - - return BadRequest("No se pudo registrar la operación."); - } - catch (Exception ex) - { - _logger.LogError(ex, "Error al crear operación {Noperacion}", operacion.Noperacion); - return StatusCode(500, "Ocurrió un error interno al registrar la operación."); - } - } -} diff --git a/Backend/MotoresArgentinosV2.API/Program.cs b/Backend/MotoresArgentinosV2.API/Program.cs index a86808a..e15d716 100644 --- a/Backend/MotoresArgentinosV2.API/Program.cs +++ b/Backend/MotoresArgentinosV2.API/Program.cs @@ -98,16 +98,12 @@ builder.Services.Configure(options => builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("Internet"))); -builder.Services.AddDbContext(options => - options.UseSqlServer(builder.Configuration.GetConnectionString("eldia"))); - builder.Services.AddDbContext(options => options.UseSqlServer(builder.Configuration.GetConnectionString("MotoresV2"), sqlOptions => sqlOptions.EnableRetryOnFailure())); // SERVICIOS builder.Services.AddScoped(); -builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); builder.Services.AddScoped(); diff --git a/Backend/MotoresArgentinosV2.Core/Interfaces/IOperacionesLegacyService.cs b/Backend/MotoresArgentinosV2.Core/Interfaces/IOperacionesLegacyService.cs deleted file mode 100644 index 15eb873..0000000 --- a/Backend/MotoresArgentinosV2.Core/Interfaces/IOperacionesLegacyService.cs +++ /dev/null @@ -1,38 +0,0 @@ -using MotoresArgentinosV2.Core.Entities; - -namespace MotoresArgentinosV2.Core.Interfaces; - -/// -/// Interfaz para servicios que interactúan con stored procedures legacy -/// relacionados con operaciones de pago -/// -public interface IOperacionesLegacyService -{ - /// - /// Ejecuta el SP sp_inserta_operaciones para registrar una nueva operación - /// - /// Datos de la operación a registrar - /// True si se insertó correctamente - Task InsertarOperacionAsync(Operacion operacion); - - /// - /// Obtiene operaciones por número de operación - /// - /// Número de operación a buscar - /// Lista de operaciones encontradas - Task> ObtenerOperacionesPorNumeroAsync(string noperacion); - - /// - /// Obtiene operaciones en un rango de fechas - /// - /// Fecha inicial - /// Fecha final - /// Lista de operaciones en el rango - Task> ObtenerOperacionesPorFechasAsync(DateTime fechaInicio, DateTime fechaFin); - - /// - /// Obtiene todos los medios de pago disponibles - /// - /// Lista de medios de pago - Task> ObtenerMediosDePagoAsync(); -} diff --git a/Backend/MotoresArgentinosV2.Infrastructure/Data/EldiaDbContext.cs b/Backend/MotoresArgentinosV2.Infrastructure/Data/EldiaDbContext.cs deleted file mode 100644 index be4511b..0000000 --- a/Backend/MotoresArgentinosV2.Infrastructure/Data/EldiaDbContext.cs +++ /dev/null @@ -1,85 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using MotoresArgentinosV2.Core.DTOs; -using MotoresArgentinosV2.Core.Entities; - -namespace MotoresArgentinosV2.Infrastructure.Data; - -/// -/// Contexto de Entity Framework unificado para la base de datos 'eldia' (Legacy) -/// Contiene las tablas de avisos web, operaciones, medios de pago y lógica de usuarios legacy. -/// -public class EldiaDbContext : DbContext -{ - public EldiaDbContext(DbContextOptions options) : base(options) - { - } - - // Tablas de la base 'autos' (ahora en eldia) - public DbSet Operaciones { get; set; } - public DbSet MediosDePago { get; set; } - - protected override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - - // --- Configuración de tablas ex-Autos --- - - modelBuilder.Entity(entity => - { - entity.ToTable("operaciones"); - entity.HasKey(e => e.Id); - entity.Property(e => e.Id).HasColumnName("id"); - entity.Property(e => e.Fecha).HasColumnName("fecha"); - entity.Property(e => e.Motivo).HasColumnName("motivo").HasMaxLength(50); - entity.Property(e => e.Moneda).HasColumnName("moneda").HasMaxLength(50); - entity.Property(e => e.Direccionentrega).HasColumnName("direccionentrega").HasMaxLength(50); - entity.Property(e => e.Validaciondomicilio).HasColumnName("validaciondomicilio").HasMaxLength(50); - entity.Property(e => e.Codigopedido).HasColumnName("codigopedido").HasMaxLength(50); - entity.Property(e => e.Nombreentrega).HasColumnName("nombreentrega").HasMaxLength(50); - entity.Property(e => e.Fechahora).HasColumnName("fechahora").HasMaxLength(50); - entity.Property(e => e.Telefonocomprador).HasColumnName("telefonocomprador").HasMaxLength(50); - entity.Property(e => e.Barrioentrega).HasColumnName("barrioentrega").HasMaxLength(50); - entity.Property(e => e.Codautorizacion).HasColumnName("codautorizacion").HasMaxLength(50); - entity.Property(e => e.Paisentrega).HasColumnName("paisentrega").HasMaxLength(50); - entity.Property(e => e.Cuotas).HasColumnName("cuotas").HasMaxLength(50); - entity.Property(e => e.Validafechanac).HasColumnName("validafechanac").HasMaxLength(50); - entity.Property(e => e.Validanrodoc).HasColumnName("validanrodoc").HasMaxLength(50); - entity.Property(e => e.Titular).HasColumnName("titular").HasMaxLength(50); - entity.Property(e => e.Pedido).HasColumnName("pedido").HasMaxLength(50); - entity.Property(e => e.Zipentrega).HasColumnName("zipentrega").HasMaxLength(50); - entity.Property(e => e.Monto).HasColumnName("monto").HasMaxLength(50); - entity.Property(e => e.Tarjeta).HasColumnName("tarjeta").HasMaxLength(50); - entity.Property(e => e.Fechaentrega).HasColumnName("fechaentrega").HasMaxLength(50); - entity.Property(e => e.Emailcomprador).HasColumnName("emailcomprador").HasMaxLength(50); - entity.Property(e => e.Validanropuerta).HasColumnName("validanropuerta").HasMaxLength(50); - entity.Property(e => e.Ciudadentrega).HasColumnName("ciudadentrega").HasMaxLength(50); - entity.Property(e => e.Validatipodoc).HasColumnName("validatipodoc").HasMaxLength(50); - entity.Property(e => e.Noperacion).HasColumnName("noperacion").HasMaxLength(50); - entity.Property(e => e.Estadoentrega).HasColumnName("estadoentrega").HasMaxLength(50); - entity.Property(e => e.Resultado).HasColumnName("resultado").HasMaxLength(50); - entity.Property(e => e.Mensajeentrega).HasColumnName("mensajeentrega").HasMaxLength(50); - entity.Property(e => e.Precioneto).HasColumnName("precioneto"); - }); - - modelBuilder.Entity(entity => - { - entity.ToTable("mediodepago"); - entity.HasKey(e => e.Id); - entity.Property(e => e.Id).HasColumnName("id"); - entity.Property(e => e.Mediodepago).HasColumnName("mediodepago").HasMaxLength(20); - }); - - // --- Configuración de DTOs Keyless de ex-Internet --- - - modelBuilder.Entity(e => - { - e.HasNoKey(); - e.ToView(null); - - e.Property(p => p.ImporteSiniva).HasColumnType("decimal(18,2)"); - e.Property(p => p.ImporteTotsiniva).HasColumnType("decimal(18,2)"); - e.Property(p => p.PorcentajeCombinado).HasColumnType("decimal(18,2)"); - e.Property(p => p.Centimetros).HasColumnType("decimal(18,2)"); - }); - } -} diff --git a/Backend/MotoresArgentinosV2.Infrastructure/Services/OperacionesLegacyService.cs b/Backend/MotoresArgentinosV2.Infrastructure/Services/OperacionesLegacyService.cs deleted file mode 100644 index f3d49c5..0000000 --- a/Backend/MotoresArgentinosV2.Infrastructure/Services/OperacionesLegacyService.cs +++ /dev/null @@ -1,111 +0,0 @@ -using Microsoft.Data.SqlClient; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Logging; -using MotoresArgentinosV2.Core.Entities; -using MotoresArgentinosV2.Core.Interfaces; -using MotoresArgentinosV2.Infrastructure.Data; - -namespace MotoresArgentinosV2.Infrastructure.Services; - -/// -/// Implementación del servicio para interactuar con datos legacy de operaciones -/// Utiliza EldiaDbContext para acceder a tablas y ejecutar SPs de la DB 'eldia' (ex base de datos 'autos') -/// -public class OperacionesLegacyService : IOperacionesLegacyService -{ - private readonly EldiaDbContext _context; - private readonly ILogger _logger; - - public OperacionesLegacyService(EldiaDbContext context, ILogger logger) - { - _context = context; - _logger = logger; - } - - /// - /// Ejecuta el SP sp_inserta_operaciones para registrar un pago - /// - public async Task InsertarOperacionAsync(Operacion operacion) - { - try - { - _logger.LogInformation("Ejecutando sp_inserta_operaciones para operación: {Noperacion}", operacion.Noperacion); - - // Preparar parámetros asegurando manejo de nulos - var parameters = new[] - { - new SqlParameter("@fecha", operacion.Fecha ?? (object)DBNull.Value), - new SqlParameter("@Motivo", operacion.Motivo ?? (object)DBNull.Value), - new SqlParameter("@Moneda", operacion.Moneda ?? (object)DBNull.Value), - new SqlParameter("@Direccionentrega", operacion.Direccionentrega ?? (object)DBNull.Value), - new SqlParameter("@Validaciondomicilio", operacion.Validaciondomicilio ?? (object)DBNull.Value), - new SqlParameter("@codigopedido", operacion.Codigopedido ?? (object)DBNull.Value), - new SqlParameter("@nombreentrega", operacion.Nombreentrega ?? (object)DBNull.Value), - new SqlParameter("@fechahora", operacion.Fechahora ?? (object)DBNull.Value), - new SqlParameter("@telefonocomprador", operacion.Telefonocomprador ?? (object)DBNull.Value), - new SqlParameter("@barrioentrega", operacion.Barrioentrega ?? (object)DBNull.Value), - new SqlParameter("@codautorizacion", operacion.Codautorizacion ?? (object)DBNull.Value), - new SqlParameter("@paisentrega", operacion.Paisentrega ?? (object)DBNull.Value), - new SqlParameter("@cuotas", operacion.Cuotas ?? (object)DBNull.Value), - new SqlParameter("@validafechanac", operacion.Validafechanac ?? (object)DBNull.Value), - new SqlParameter("@validanrodoc", operacion.Validanrodoc ?? (object)DBNull.Value), - new SqlParameter("@titular", operacion.Titular ?? (object)DBNull.Value), - new SqlParameter("@pedido", operacion.Pedido ?? (object)DBNull.Value), - new SqlParameter("@zipentrega", operacion.Zipentrega ?? (object)DBNull.Value), - new SqlParameter("@monto", operacion.Monto ?? (object)DBNull.Value), - new SqlParameter("@tarjeta", operacion.Tarjeta ?? (object)DBNull.Value), - new SqlParameter("@fechaentrega", operacion.Fechaentrega ?? (object)DBNull.Value), - new SqlParameter("@emailcomprador", operacion.Emailcomprador ?? (object)DBNull.Value), - new SqlParameter("@validanropuerta", operacion.Validanropuerta ?? (object)DBNull.Value), - new SqlParameter("@ciudadentrega", operacion.Ciudadentrega ?? (object)DBNull.Value), - new SqlParameter("@validatipodoc", operacion.Validatipodoc ?? (object)DBNull.Value), - new SqlParameter("@noperacion", operacion.Noperacion ?? (object)DBNull.Value), - new SqlParameter("@estadoentrega", operacion.Estadoentrega ?? (object)DBNull.Value), - new SqlParameter("@resultado", operacion.Resultado ?? (object)DBNull.Value), - new SqlParameter("@mensajeentrega", operacion.Mensajeentrega ?? (object)DBNull.Value), - new SqlParameter("@precio", operacion.Precioneto ?? 0) // El SP espera int - }; - - await _context.Database.ExecuteSqlRawAsync( - "EXEC dbo.sp_inserta_operaciones @fecha, @Motivo, @Moneda, @Direccionentrega, " + - "@Validaciondomicilio, @codigopedido, @nombreentrega, @fechahora, @telefonocomprador, " + - "@barrioentrega, @codautorizacion, @paisentrega, @cuotas, @validafechanac, @validanrodoc, " + - "@titular, @pedido, @zipentrega, @monto, @tarjeta, @fechaentrega, @emailcomprador, " + - "@validanropuerta, @ciudadentrega, @validatipodoc, @noperacion, @estadoentrega, " + - "@resultado, @mensajeentrega, @precio", - parameters); - - _logger.LogInformation("Operación registrada correctamente: {Noperacion}", operacion.Noperacion); - return true; - } - catch (Exception ex) - { - _logger.LogError(ex, "Error al insertar operación: {Noperacion}", operacion.Noperacion); - throw; - } - } - - public async Task> ObtenerOperacionesPorNumeroAsync(string noperacion) - { - return await _context.Operaciones - .AsNoTracking() - .Where(o => o.Noperacion == noperacion) - .ToListAsync(); - } - - public async Task> ObtenerOperacionesPorFechasAsync(DateTime fechaInicio, DateTime fechaFin) - { - return await _context.Operaciones - .AsNoTracking() - .Where(o => o.Fecha >= fechaInicio && o.Fecha <= fechaFin) - .OrderByDescending(o => o.Fecha) - .ToListAsync(); - } - - public async Task> ObtenerMediosDePagoAsync() - { - return await _context.MediosDePago - .AsNoTracking() - .ToListAsync(); - } -}