From 97d764dfb315728835936bb10e29190afcc0150e Mon Sep 17 00:00:00 2001 From: Claudiu Farcas Date: Mon, 10 Jul 2023 14:28:39 +0000 Subject: [PATCH] reorganise --- src/mysol.sln | 22 ++++++++++ .../Controllers/WeatherForecastController.cs | 32 +++++++++++++++ src/webapi/Program.cs | 25 +++++++++++ src/webapi/Properties/launchSettings.json | 41 +++++++++++++++++++ src/webapi/WeatherForecast.cs | 12 ++++++ src/webapi/appsettings.Development.json | 8 ++++ src/webapi/appsettings.json | 9 ++++ src/webapi/webapi.csproj | 14 +++++++ 8 files changed, 163 insertions(+) create mode 100644 src/mysol.sln create mode 100644 src/webapi/Controllers/WeatherForecastController.cs create mode 100644 src/webapi/Program.cs create mode 100644 src/webapi/Properties/launchSettings.json create mode 100644 src/webapi/WeatherForecast.cs create mode 100644 src/webapi/appsettings.Development.json create mode 100644 src/webapi/appsettings.json create mode 100644 src/webapi/webapi.csproj diff --git a/src/mysol.sln b/src/mysol.sln new file mode 100644 index 0000000..abc8d41 --- /dev/null +++ b/src/mysol.sln @@ -0,0 +1,22 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "webapi", "webapi\webapi.csproj", "{16845CB2-B383-459D-9C34-B384160F2D18}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {16845CB2-B383-459D-9C34-B384160F2D18}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {16845CB2-B383-459D-9C34-B384160F2D18}.Debug|Any CPU.Build.0 = Debug|Any CPU + {16845CB2-B383-459D-9C34-B384160F2D18}.Release|Any CPU.ActiveCfg = Release|Any CPU + {16845CB2-B383-459D-9C34-B384160F2D18}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection +EndGlobal diff --git a/src/webapi/Controllers/WeatherForecastController.cs b/src/webapi/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..f11a562 --- /dev/null +++ b/src/webapi/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +namespace webapi.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/src/webapi/Program.cs b/src/webapi/Program.cs new file mode 100644 index 0000000..15eacee --- /dev/null +++ b/src/webapi/Program.cs @@ -0,0 +1,25 @@ +var builder = WebApplication.CreateBuilder(args); + +// Add services to the container. + +builder.Services.AddControllers(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + +var app = builder.Build(); + +// Configure the HTTP request pipeline. +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + +app.UseHttpsRedirection(); + +app.UseAuthorization(); + +app.MapControllers(); + +app.Run(); diff --git a/src/webapi/Properties/launchSettings.json b/src/webapi/Properties/launchSettings.json new file mode 100644 index 0000000..cf12495 --- /dev/null +++ b/src/webapi/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:62879", + "sslPort": 44305 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5228", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7013;http://localhost:5228", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/webapi/WeatherForecast.cs b/src/webapi/WeatherForecast.cs new file mode 100644 index 0000000..3ea7355 --- /dev/null +++ b/src/webapi/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace webapi; + +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/src/webapi/appsettings.Development.json b/src/webapi/appsettings.Development.json new file mode 100644 index 0000000..ff66ba6 --- /dev/null +++ b/src/webapi/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/webapi/appsettings.json b/src/webapi/appsettings.json new file mode 100644 index 0000000..4d56694 --- /dev/null +++ b/src/webapi/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/src/webapi/webapi.csproj b/src/webapi/webapi.csproj new file mode 100644 index 0000000..0988016 --- /dev/null +++ b/src/webapi/webapi.csproj @@ -0,0 +1,14 @@ + + + + net7.0 + enable + enable + + + + + + + +