commit b6d174bf1b3a4eb201d3b10ce1e138e75b5b35d4 Author: Fernando Araoz Date: Fri Jan 24 06:27:32 2025 -0500 Init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..98ff247 --- /dev/null +++ b/.gitignore @@ -0,0 +1,34 @@ +[Bb]in/ +[Oo]bj/ + +.vs/ +.idea/ +*.user +*.userosscache +*.sln.docstates +*.suo + +*.DS_Store +Thumbs.db + +.idea/ +*.sln.iml +.idea/**/workspace.xml + +appsettings.*.json +!appsettings.json +!appsettings.Example.json + +*.dbmdl +*.jfm +*.pfx +*.publishsettings + +*.nupkg +**/packages/* +!**/packages/build/ +*.nuget.props +*.nuget.targets + +# build artifacts +out diff --git a/Controllers/WeatherForecastController.cs b/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..979a771 --- /dev/null +++ b/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace MyApp.Controllers; + +[ApiController] +[Route("[controller]")] +public class WeatherForecastController : ControllerBase +{ + private static readonly string[] Summaries = new[] + { + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + }; + + private readonly ILogger _logger; + + public WeatherForecastController(ILogger logger) + { + _logger = logger; + } + + [HttpGet(Name = "GetWeatherForecast")] + public IEnumerable Get() + { + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } +} diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md new file mode 100644 index 0000000..9f756b4 --- /dev/null +++ b/DOCUMENTATION.md @@ -0,0 +1,30 @@ +# Documentacion + +ASP.NET core controllers API 9.0 + +https://dotnet.microsoft.com/en-us/apps/aspnet + +## Tipos de APIs en aspnet + +- Minimal - Parecido a express +- Controllers - Parecido a Nestjs, estructurado, completo + +- [aspnet core 9 api](https://learn.microsoft.com/en-us/aspnet/core/fundamentals/apis?view=aspnetcore-9.0) +- [aspnet controllers](https://learn.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-9.0) +- [tutorial para crear proyecto nuevo](https://learn.microsoft.com/en-us/aspnet/core/tutorials/first-web-api?view=aspnetcore-9.0) + +## Creación del proyecto + +> Reemplazar `MyApp` con el nombre del proyecto, por ejemplo `Trazo`. + +Con Docker, ejecutar el comando: + +```sh +docker run --rm -v $(pwd):/app mcr.microsoft.com/dotnet/sdk:9.0 sh -c "cd /app && dotnet new webapi --use-controllers -o MyApp && chown -R $(id -u):$(id -g) MyApp" +``` + +para crear un proyecto nuevo, vacio, sin tener que instalar ningun programa. + + + + diff --git a/MyApp.csproj b/MyApp.csproj new file mode 100644 index 0000000..85983f6 --- /dev/null +++ b/MyApp.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + diff --git a/Program.cs b/Program.cs new file mode 100644 index 0000000..6189b36 --- /dev/null +++ b/Program.cs @@ -0,0 +1,23 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// 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(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/Properties/launchSettings.json b/Properties/launchSettings.json new file mode 100644 index 0000000..5275c03 --- /dev/null +++ b/Properties/launchSettings.json @@ -0,0 +1,23 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "http://localhost:5280", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7042;http://localhost:5280", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/WeatherForecast.cs b/WeatherForecast.cs new file mode 100644 index 0000000..e0a7f26 --- /dev/null +++ b/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace MyApp; + +public class WeatherForecast +{ + public DateOnly Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string? Summary { get; set; } +} diff --git a/appsettings.json b/appsettings.json new file mode 100644 index 0000000..4d56694 --- /dev/null +++ b/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}