diff --git a/src/Mercados.Api/Mercados.Api.csproj b/src/Mercados.Api/Mercados.Api.csproj index 8c7c090..82b7c07 100644 --- a/src/Mercados.Api/Mercados.Api.csproj +++ b/src/Mercados.Api/Mercados.Api.csproj @@ -7,7 +7,9 @@ + + diff --git a/src/Mercados.Api/Program.cs b/src/Mercados.Api/Program.cs index ee9d65d..fdf6797 100644 --- a/src/Mercados.Api/Program.cs +++ b/src/Mercados.Api/Program.cs @@ -1,41 +1,31 @@ +// Importamos los namespaces necesarios +using Mercados.Infrastructure; +using Mercados.Infrastructure.Persistence; + var builder = WebApplication.CreateBuilder(args); +// 1. Registramos nuestra fábrica de conexiones como un Singleton. +// Solo se creará una instancia que leerá la configuration una vez. +builder.Services.AddSingleton(); + // Add services to the container. -// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi -builder.Services.AddOpenApi(); +builder.Services.AddControllers(); +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); var app = builder.Build(); // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { - app.MapOpenApi(); + app.UseSwagger(); + app.UseSwaggerUI(); } app.UseHttpsRedirection(); -var summaries = new[] -{ - "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" -}; +app.UseAuthorization(); -app.MapGet("/weatherforecast", () => -{ - var forecast = Enumerable.Range(1, 5).Select(index => - new WeatherForecast - ( - DateOnly.FromDateTime(DateTime.Now.AddDays(index)), - Random.Shared.Next(-20, 55), - summaries[Random.Shared.Next(summaries.Length)] - )) - .ToArray(); - return forecast; -}) -.WithName("GetWeatherForecast"); +app.MapControllers(); -app.Run(); - -record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary) -{ - public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); -} +app.Run(); \ No newline at end of file diff --git a/src/Mercados.Api/appsettings.json b/src/Mercados.Api/appsettings.json index 10f68b8..71f17dd 100644 --- a/src/Mercados.Api/appsettings.json +++ b/src/Mercados.Api/appsettings.json @@ -5,5 +5,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "AllowedHosts": "*" -} + "AllowedHosts": "*", + "ConnectionStrings": { + "DefaultConnection": "Server=TECNICA3;Database=MercadosDb;User Id=mercadosuser;Password=@mercados1351@;Trusted_Connection=False;Encrypt=False;" + } +} \ No newline at end of file diff --git a/src/Mercados.Core/Class1.cs b/src/Mercados.Core/Class1.cs deleted file mode 100644 index b48b8f0..0000000 --- a/src/Mercados.Core/Class1.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Mercados.Core; - -public class Class1 -{ - -} diff --git a/src/Mercados.Core/Entities/CotizacionBolsa.cs b/src/Mercados.Core/Entities/CotizacionBolsa.cs new file mode 100644 index 0000000..22eaf00 --- /dev/null +++ b/src/Mercados.Core/Entities/CotizacionBolsa.cs @@ -0,0 +1,14 @@ +namespace Mercados.Core.Entities +{ + public class CotizacionBolsa + { + public long Id { get; set; } + public string Ticker { get; set; } = string.Empty; // "AAPL", "GGAL.BA", etc. + public string Mercado { get; set; } = string.Empty; // "EEUU" o "Local" + public decimal PrecioActual { get; set; } + public decimal Apertura { get; set; } + public decimal CierreAnterior { get; set; } + public decimal PorcentajeCambio { get; set; } + public DateTime FechaRegistro { get; set; } + } +} \ No newline at end of file diff --git a/src/Mercados.Core/Entities/CotizacionGanado.cs b/src/Mercados.Core/Entities/CotizacionGanado.cs new file mode 100644 index 0000000..0950392 --- /dev/null +++ b/src/Mercados.Core/Entities/CotizacionGanado.cs @@ -0,0 +1,18 @@ +namespace Mercados.Core.Entities +{ + public class CotizacionGanado + { + public long Id { get; set; } + public string Categoria { get; set; } = string.Empty; + public string Especificaciones { get; set; } = string.Empty; + public decimal Maximo { get; set; } + public decimal Minimo { get; set; } + public decimal Promedio { get; set; } + public decimal Mediano { get; set; } + public int Cabezas { get; set; } + public int KilosTotales { get; set; } + public int KilosPorCabeza { get; set; } + public decimal ImporteTotal { get; set; } + public DateTime FechaRegistro { get; set; } + } +} \ No newline at end of file diff --git a/src/Mercados.Core/Entities/CotizacionGrano.cs b/src/Mercados.Core/Entities/CotizacionGrano.cs new file mode 100644 index 0000000..60ce45f --- /dev/null +++ b/src/Mercados.Core/Entities/CotizacionGrano.cs @@ -0,0 +1,12 @@ +namespace Mercados.Core.Entities +{ + public class CotizacionGrano + { + public long Id { get; set; } + public string Nombre { get; set; } = string.Empty; // "Soja", "Trigo", etc. + public decimal Precio { get; set; } + public decimal VariacionPrecio { get; set; } + public DateTime FechaOperacion { get; set; } + public DateTime FechaRegistro { get; set; } + } +} \ No newline at end of file diff --git a/src/Mercados.Core/Entities/FuenteDato.cs b/src/Mercados.Core/Entities/FuenteDato.cs new file mode 100644 index 0000000..780f78e --- /dev/null +++ b/src/Mercados.Core/Entities/FuenteDato.cs @@ -0,0 +1,10 @@ +namespace Mercados.Core.Entities +{ + public class FuenteDato + { + public long Id { get; set; } + public string Nombre { get; set; } = string.Empty; // "BCR", "Finnhub", "YahooFinance", "MercadoAgroganadero" + public DateTime UltimaEjecucionExitosa { get; set; } + public string? Url { get; set; } + } +} \ No newline at end of file diff --git a/src/Mercados.Database/Mercados.Database.csproj b/src/Mercados.Database/Mercados.Database.csproj index 125f4c9..5ad11ce 100644 --- a/src/Mercados.Database/Mercados.Database.csproj +++ b/src/Mercados.Database/Mercados.Database.csproj @@ -6,4 +6,9 @@ enable + + + + + diff --git a/src/Mercados.Infrastructure/Mercados.Infrastructure.csproj b/src/Mercados.Infrastructure/Mercados.Infrastructure.csproj index bfbcf29..d982fbc 100644 --- a/src/Mercados.Infrastructure/Mercados.Infrastructure.csproj +++ b/src/Mercados.Infrastructure/Mercados.Infrastructure.csproj @@ -4,6 +4,12 @@ + + + + + + net9.0 enable diff --git a/src/Mercados.Infrastructure/Persistence/IDbConnectionFactory.cs b/src/Mercados.Infrastructure/Persistence/IDbConnectionFactory.cs new file mode 100644 index 0000000..579b5b8 --- /dev/null +++ b/src/Mercados.Infrastructure/Persistence/IDbConnectionFactory.cs @@ -0,0 +1,9 @@ +using System.Data; + +namespace Mercados.Infrastructure.Persistence +{ + public interface IDbConnectionFactory + { + IDbConnection CreateConnection(); + } +} \ No newline at end of file diff --git a/src/Mercados.Infrastructure/Persistence/SqlConnectionFactory.cs b/src/Mercados.Infrastructure/Persistence/SqlConnectionFactory.cs new file mode 100644 index 0000000..50d01bb --- /dev/null +++ b/src/Mercados.Infrastructure/Persistence/SqlConnectionFactory.cs @@ -0,0 +1,24 @@ +using Mercados.Infrastructure.Persistence; +using Microsoft.Data.SqlClient; +using Microsoft.Extensions.Configuration; +using System.Data; + +namespace Mercados.Infrastructure +{ + public class SqlConnectionFactory : IDbConnectionFactory + { + private readonly string _connectionString; + + public SqlConnectionFactory(IConfiguration configuration) + { + _connectionString = configuration.GetConnectionString("DefaultConnection") + ?? throw new ArgumentNullException(nameof(configuration), "La cadena de conexión 'DefaultConnection' no fue encontrada."); + } + + public IDbConnection CreateConnection() + { + // Dapper se encargará de abrir y cerrar la conexión automáticamente. + return new SqlConnection(_connectionString); + } + } +} \ No newline at end of file