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;"
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user