From 975c42762c78e14aee13f7b4f89ea97229545345 Mon Sep 17 00:00:00 2001 From: Fernando Araoz Date: Fri, 10 Jan 2025 17:01:50 -0500 Subject: [PATCH] init --- .gitignore | 39 ++++++++++++++++++++++++ Controllers/WeatherForecastController.cs | 32 +++++++++++++++++++ Dockerfile | 10 ++++++ Program.cs | 23 ++++++++++++++ Properties/launchSettings.json | 23 ++++++++++++++ WeatherForecast.cs | 12 ++++++++ appsettings.json | 9 ++++++ csharp.csproj | 13 ++++++++ csharp.http | 6 ++++ docker-compose.yml | 12 ++++++++ 10 files changed, 179 insertions(+) create mode 100644 .gitignore create mode 100644 Controllers/WeatherForecastController.cs create mode 100644 Dockerfile create mode 100644 Program.cs create mode 100644 Properties/launchSettings.json create mode 100644 WeatherForecast.cs create mode 100644 appsettings.json create mode 100644 csharp.csproj create mode 100644 csharp.http create mode 100644 docker-compose.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8e88a90 --- /dev/null +++ b/.gitignore @@ -0,0 +1,39 @@ +# Binary garbage +[Bb]in/ +[Oo]bj/ + +# IDE trash +.vs/ +.idea/ +*.user +*.userosscache +*.sln.docstates +*.suo + +# That stupid Windows file +*.DS_Store +Thumbs.db + +# Rider's mess +.idea/ +*.sln.iml +.idea/**/workspace.xml + +# ASP.NET's "secrets" (as if anything Microsoft makes could be secure) +appsettings.*.json +!appsettings.json +!appsettings.Example.json + +# MSBuild junk +*.dbmdl +*.jfm +*.pfx +*.publishsettings + +# NuGet waste (because apparently one package manager wasn't enough) +*.nupkg +**/packages/* +!**/packages/build/ +*.nuget.props +*.nuget.targets + diff --git a/Controllers/WeatherForecastController.cs b/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..5dbdcb0 --- /dev/null +++ b/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace csharp.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/Dockerfile b/Dockerfile new file mode 100644 index 0000000..08980e3 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM mcr.microsoft.com/dotnet/sdk:9.0 + +WORKDIR /app + +# Set ASP.NET to actually listen on all interfaces, not just localhost +ENV ASPNETCORE_URLS=http://+:5266 +# Allow non-HTTPS because it's just development, who cares +ENV ASPNETCORE_ENVIRONMENT=Development + +ENTRYPOINT ["dotnet", "watch", "run", "--no-launch-profile"] 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..fa9df86 --- /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:5266", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7284;http://localhost:5266", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/WeatherForecast.cs b/WeatherForecast.cs new file mode 100644 index 0000000..3e1a269 --- /dev/null +++ b/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace csharp; + +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": "*" +} diff --git a/csharp.csproj b/csharp.csproj new file mode 100644 index 0000000..bcb7bd3 --- /dev/null +++ b/csharp.csproj @@ -0,0 +1,13 @@ + + + + net9.0 + enable + enable + + + + + + + diff --git a/csharp.http b/csharp.http new file mode 100644 index 0000000..da5d8d7 --- /dev/null +++ b/csharp.http @@ -0,0 +1,6 @@ +@csharp_HostAddress = http://localhost:5266 + +GET {{csharp_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..0104f5f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +services: + aspnet-prison: + container_name: aspnet-prison + user: "1001:1001" + build: + context: . + dockerfile: Dockerfile + ports: + - "5266:5266" + volumes: + - ./:/app +