feat: Define data models and set up DB connection with Dapper
This commit is contained in:
		| @@ -7,7 +7,9 @@ | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="FluentMigrator.Runner" Version="7.1.0" /> | ||||
|     <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.5" /> | ||||
|     <PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.1" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|   | ||||
| @@ -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<IDbConnectionFactory, SqlConnectionFactory>(); | ||||
|  | ||||
| // 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(); | ||||
| @@ -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;" | ||||
|   } | ||||
| } | ||||
| @@ -1,6 +0,0 @@ | ||||
| namespace Mercados.Core; | ||||
|  | ||||
| public class Class1 | ||||
| { | ||||
|  | ||||
| } | ||||
							
								
								
									
										14
									
								
								src/Mercados.Core/Entities/CotizacionBolsa.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								src/Mercados.Core/Entities/CotizacionBolsa.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -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; } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										18
									
								
								src/Mercados.Core/Entities/CotizacionGanado.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										18
									
								
								src/Mercados.Core/Entities/CotizacionGanado.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -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; } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										12
									
								
								src/Mercados.Core/Entities/CotizacionGrano.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/Mercados.Core/Entities/CotizacionGrano.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -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; } | ||||
|   } | ||||
| } | ||||
							
								
								
									
										10
									
								
								src/Mercados.Core/Entities/FuenteDato.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								src/Mercados.Core/Entities/FuenteDato.cs
									
									
									
									
									
										Normal file
									
								
							| @@ -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; } | ||||
|   } | ||||
| } | ||||
| @@ -6,4 +6,9 @@ | ||||
|     <Nullable>enable</Nullable> | ||||
|   </PropertyGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="FluentMigrator" Version="7.1.0" /> | ||||
|     <PackageReference Include="FluentMigrator.Runner" Version="7.1.0" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
| </Project> | ||||
|   | ||||
| @@ -4,6 +4,12 @@ | ||||
|     <ProjectReference Include="..\Mercados.Core\Mercados.Core.csproj" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <ItemGroup> | ||||
|     <PackageReference Include="Dapper" Version="2.1.66" /> | ||||
|     <PackageReference Include="Microsoft.Data.SqlClient" Version="6.0.2" /> | ||||
|     <PackageReference Include="Microsoft.Extensions.Http" Version="9.0.6" /> | ||||
|   </ItemGroup> | ||||
|  | ||||
|   <PropertyGroup> | ||||
|     <TargetFramework>net9.0</TargetFramework> | ||||
|     <ImplicitUsings>enable</ImplicitUsings> | ||||
|   | ||||
| @@ -0,0 +1,9 @@ | ||||
| using System.Data; | ||||
|  | ||||
| namespace Mercados.Infrastructure.Persistence | ||||
| { | ||||
|   public interface IDbConnectionFactory | ||||
|   { | ||||
|     IDbConnection CreateConnection(); | ||||
|   } | ||||
| } | ||||
| @@ -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); | ||||
|     } | ||||
|   } | ||||
| } | ||||
		Reference in New Issue
	
	Block a user