Init Commit

This commit is contained in:
2026-01-29 13:43:44 -03:00
commit b9aa8478db
126 changed files with 20649 additions and 0 deletions

View File

@@ -0,0 +1,119 @@
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<OperacionesLegacyController> _logger;
public OperacionesLegacyController(IOperacionesLegacyService operacionesService, ILogger<OperacionesLegacyController> logger)
{
_operacionesService = operacionesService;
_logger = logger;
}
/// <summary>
/// Obtiene los medios de pago disponibles
/// </summary>
[HttpGet("medios-pago")]
public async Task<ActionResult<List<MedioDePago>>> 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");
}
}
/// <summary>
/// Busca una operación por su número de operación
/// </summary>
[HttpGet("{noperacion}")]
public async Task<ActionResult<List<Operacion>>> 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");
}
}
/// <summary>
/// Obtiene operaciones realizadas en un rango de fechas
/// </summary>
[HttpGet("buscar")]
public async Task<ActionResult<List<Operacion>>> 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.");
}
}
/// <summary>
/// Registra una nueva operación de pago
/// </summary>
[HttpPost]
public async Task<ActionResult> 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.");
}
}
}