feat: Define data models and set up DB connection with Dapper
This commit is contained in:
		| @@ -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(); | ||||
		Reference in New Issue
	
	Block a user