feat: Initial project structure for Clima application
This commit is contained in:
20
src/Clima.Api/Clima.Api.csproj
Normal file
20
src/Clima.Api/Clima.Api.csproj
Normal file
@@ -0,0 +1,20 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</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.3" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Clima.Infrastructure\Clima.Infrastructure.csproj" />
|
||||
<ProjectReference Include="..\Clima.Database\Clima.Database.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
6
src/Clima.Api/Clima.Api.http
Normal file
6
src/Clima.Api/Clima.Api.http
Normal file
@@ -0,0 +1,6 @@
|
||||
@Clima.Api_HostAddress = http://localhost:5036
|
||||
|
||||
GET {{Clima.Api_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
41
src/Clima.Api/Program.cs
Normal file
41
src/Clima.Api/Program.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
var summaries = new[]
|
||||
{
|
||||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
|
||||
};
|
||||
|
||||
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.Run();
|
||||
|
||||
record WeatherForecast(DateOnly Date, int TemperatureC, string? Summary)
|
||||
{
|
||||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
|
||||
}
|
||||
23
src/Clima.Api/Properties/launchSettings.json
Normal file
23
src/Clima.Api/Properties/launchSettings.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"http": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "http://localhost:5036",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
},
|
||||
"https": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"launchBrowser": false,
|
||||
"applicationUrl": "https://localhost:7098;http://localhost:5036",
|
||||
"environmentVariables": {
|
||||
"ASPNETCORE_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/Clima.Api/appsettings.Development.json
Normal file
8
src/Clima.Api/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
}
|
||||
}
|
||||
9
src/Clima.Api/appsettings.json
Normal file
9
src/Clima.Api/appsettings.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
}
|
||||
9
src/Clima.Core/Clima.Core.csproj
Normal file
9
src/Clima.Core/Clima.Core.csproj
Normal file
@@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
13
src/Clima.Core/Entities/Pronostico.cs
Normal file
13
src/Clima.Core/Entities/Pronostico.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace Clima.Core.Entities
|
||||
{
|
||||
public class Pronostico
|
||||
{
|
||||
public long Id { get; set; }
|
||||
public string Estacion { get; set; } = string.Empty;
|
||||
public DateTime FechaHora { get; set; }
|
||||
public decimal TemperaturaC { get; set; }
|
||||
public int VientoDirGrados { get; set; }
|
||||
public int VientoKmh { get; set; }
|
||||
public decimal PrecipitacionMm { get; set; }
|
||||
}
|
||||
}
|
||||
14
src/Clima.Database/Clima.Database.csproj
Normal file
14
src/Clima.Database/Clima.Database.csproj
Normal file
@@ -0,0 +1,14 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="FluentMigrator" Version="7.1.0" />
|
||||
<PackageReference Include="FluentMigrator.Runner" Version="7.1.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,33 @@
|
||||
using FluentMigrator;
|
||||
|
||||
namespace Clima.Database.Migrations
|
||||
{
|
||||
[Migration(20250725130000)]
|
||||
public class CreatePronosticoTable : Migration
|
||||
{
|
||||
private const string TableName = "Pronosticos";
|
||||
|
||||
public override void Up()
|
||||
{
|
||||
Create.Table(TableName)
|
||||
.WithColumn("Id").AsInt64().PrimaryKey().Identity()
|
||||
.WithColumn("Estacion").AsString(100).NotNullable()
|
||||
.WithColumn("FechaHora").AsDateTime2().NotNullable()
|
||||
.WithColumn("TemperaturaC").AsDecimal(5, 1).NotNullable()
|
||||
.WithColumn("VientoDirGrados").AsInt32().NotNullable()
|
||||
.WithColumn("VientoKmh").AsInt32().NotNullable()
|
||||
.WithColumn("PrecipitacionMm").AsDecimal(5, 1).NotNullable();
|
||||
|
||||
Create.Index($"IX_{TableName}_Estacion_FechaHora")
|
||||
.OnTable(TableName)
|
||||
.OnColumn("Estacion").Ascending()
|
||||
.OnColumn("FechaHora").Ascending();
|
||||
}
|
||||
|
||||
public override void Down()
|
||||
{
|
||||
Delete.Index($"IX_{TableName}_Estacion_FechaHora").OnTable(TableName);
|
||||
Delete.Table(TableName);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
src/Clima.Infrastructure/Clima.Infrastructure.csproj
Normal file
19
src/Clima.Infrastructure/Clima.Infrastructure.csproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Clima.Core\Clima.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.7" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,10 @@
|
||||
using Clima.Core.Entities;
|
||||
|
||||
namespace Clima.Infrastructure.Persistence.Repositories
|
||||
{
|
||||
public interface IPronosticoRepository
|
||||
{
|
||||
Task<IEnumerable<Pronostico>> ObtenerPorEstacionAsync(string nombreEstacion);
|
||||
Task ReemplazarPronosticosPorEstacionAsync(string nombreEstacion, IEnumerable<Pronostico> pronosticos);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
using Dapper;
|
||||
using Clima.Core.Entities;
|
||||
using Clima.Infrastructure.Persistence; // Para IDbConnectionFactory
|
||||
using System.Data;
|
||||
|
||||
namespace Clima.Infrastructure.Persistence.Repositories
|
||||
{
|
||||
public class PronosticoRepository : IPronosticoRepository
|
||||
{
|
||||
private readonly IDbConnectionFactory _dbConnectionFactory;
|
||||
|
||||
public PronosticoRepository(IDbConnectionFactory dbConnectionFactory)
|
||||
{
|
||||
_dbConnectionFactory = dbConnectionFactory;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<Pronostico>> ObtenerPorEstacionAsync(string nombreEstacion)
|
||||
{
|
||||
using var connection = _dbConnectionFactory.CreateConnection();
|
||||
const string sql = "SELECT * FROM Pronosticos WHERE Estacion = @NombreEstacion ORDER BY FechaHora ASC;";
|
||||
return await connection.QueryAsync<Pronostico>(sql, new { NombreEstacion = nombreEstacion });
|
||||
}
|
||||
|
||||
public async Task ReemplazarPronosticosPorEstacionAsync(string nombreEstacion, IEnumerable<Pronostico> pronosticos)
|
||||
{
|
||||
using var connection = _dbConnectionFactory.CreateConnection();
|
||||
connection.Open();
|
||||
using var transaction = connection.BeginTransaction();
|
||||
try
|
||||
{
|
||||
const string deleteSql = "DELETE FROM Pronosticos WHERE Estacion = @NombreEstacion;";
|
||||
await connection.ExecuteAsync(deleteSql, new { NombreEstacion = nombreEstacion }, transaction);
|
||||
|
||||
const string insertSql = @"
|
||||
INSERT INTO Pronosticos (Estacion, FechaHora, TemperaturaC, VientoDirGrados, VientoKmh, PrecipitacionMm)
|
||||
VALUES (@Estacion, @FechaHora, @TemperaturaC, @VientoDirGrados, @VientoKmh, @PrecipitacionMm);";
|
||||
await connection.ExecuteAsync(insertSql, pronosticos, transaction);
|
||||
|
||||
transaction.Commit();
|
||||
}
|
||||
catch
|
||||
{
|
||||
transaction.Rollback();
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
src/Clima.Worker/Clima.Worker.csproj
Normal file
18
src/Clima.Worker/Clima.Worker.csproj
Normal file
@@ -0,0 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Worker">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net9.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<UserSecretsId>dotnet-Clima.Worker-322ab7e4-65cf-4c89-b0cf-47a738df31a0</UserSecretsId>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Hosting" Version="9.0.5" />
|
||||
<PackageReference Include="Microsoft.Extensions.Http.Polly" Version="9.0.7" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Clima.Infrastructure\Clima.Infrastructure.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
7
src/Clima.Worker/Program.cs
Normal file
7
src/Clima.Worker/Program.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using Clima.Worker;
|
||||
|
||||
var builder = Host.CreateApplicationBuilder(args);
|
||||
builder.Services.AddHostedService<Worker>();
|
||||
|
||||
var host = builder.Build();
|
||||
host.Run();
|
||||
12
src/Clima.Worker/Properties/launchSettings.json
Normal file
12
src/Clima.Worker/Properties/launchSettings.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/launchsettings.json",
|
||||
"profiles": {
|
||||
"Clima.Worker": {
|
||||
"commandName": "Project",
|
||||
"dotnetRunMessages": true,
|
||||
"environmentVariables": {
|
||||
"DOTNET_ENVIRONMENT": "Development"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
23
src/Clima.Worker/Worker.cs
Normal file
23
src/Clima.Worker/Worker.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
namespace Clima.Worker;
|
||||
|
||||
public class Worker : BackgroundService
|
||||
{
|
||||
private readonly ILogger<Worker> _logger;
|
||||
|
||||
public Worker(ILogger<Worker> logger)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
|
||||
protected override async Task ExecuteAsync(CancellationToken stoppingToken)
|
||||
{
|
||||
while (!stoppingToken.IsCancellationRequested)
|
||||
{
|
||||
if (_logger.IsEnabled(LogLevel.Information))
|
||||
{
|
||||
_logger.LogInformation("Worker running at: {time}", DateTimeOffset.Now);
|
||||
}
|
||||
await Task.Delay(1000, stoppingToken);
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/Clima.Worker/appsettings.Development.json
Normal file
8
src/Clima.Worker/appsettings.Development.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
8
src/Clima.Worker/appsettings.json
Normal file
8
src/Clima.Worker/appsettings.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"Logging": {
|
||||
"LogLevel": {
|
||||
"Default": "Information",
|
||||
"Microsoft.Hosting.Lifetime": "Information"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user