diff --git a/CityInfo.API/CityInfo.API.csproj b/CityInfo.API/CityInfo.API.csproj new file mode 100644 index 0000000..39f3cde --- /dev/null +++ b/CityInfo.API/CityInfo.API.csproj @@ -0,0 +1,14 @@ + + + + net10.0 + enable + enable + + + + + + + + diff --git a/CityInfo.API/CityInfo.API.http b/CityInfo.API/CityInfo.API.http new file mode 100644 index 0000000..ca0985d --- /dev/null +++ b/CityInfo.API/CityInfo.API.http @@ -0,0 +1,6 @@ +@CityInfo.API_HostAddress = http://localhost:5244 + +GET {{CityInfo.API_HostAddress}}/weatherforecast/ +Accept: application/json + +### diff --git a/CityInfo.API/Controllers/WeatherForecastController.cs b/CityInfo.API/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..19d9710 --- /dev/null +++ b/CityInfo.API/Controllers/WeatherForecastController.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Mvc; + +namespace CityInfo.API.Controllers +{ + [ApiController] + [Route("[controller]")] + public class WeatherForecastController : ControllerBase + { + private static readonly string[] Summaries = + [ + "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" + ]; + + [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/CityInfo.API/Program.cs b/CityInfo.API/Program.cs new file mode 100644 index 0000000..6101d42 --- /dev/null +++ b/CityInfo.API/Program.cs @@ -0,0 +1,28 @@ +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.UseSwaggerUI(options => + { + options.SwaggerEndpoint("/openapi/v1.json", "API v1"); + }); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/CityInfo.API/Properties/launchSettings.json b/CityInfo.API/Properties/launchSettings.json new file mode 100644 index 0000000..24981f2 --- /dev/null +++ b/CityInfo.API/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:5244", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": false, + "applicationUrl": "https://localhost:7289;http://localhost:5244", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/CityInfo.API/WeatherForecast.cs b/CityInfo.API/WeatherForecast.cs new file mode 100644 index 0000000..944c31f --- /dev/null +++ b/CityInfo.API/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace CityInfo.API +{ + 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/CityInfo.API/appsettings.Development.json b/CityInfo.API/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/CityInfo.API/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/CityInfo.API/appsettings.json b/CityInfo.API/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/CityInfo.API/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/CityInfo.slnx b/CityInfo.slnx new file mode 100644 index 0000000..64a9c86 --- /dev/null +++ b/CityInfo.slnx @@ -0,0 +1,3 @@ + + +