From cde9db97fbf4f911120f025410f278a128339e7a Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Tue, 29 Jun 2021 10:35:12 +0200 Subject: [PATCH] Aggiunta preliminare progetto GWMS.API x test swagger (unused) --- .../Controllers/WeatherForecastController.cs | 39 ++++++++++++ GWMS.API/GWMS.API.csproj | 11 ++++ GWMS.API/Program.cs | 26 ++++++++ GWMS.API/Properties/launchSettings.json | 31 ++++++++++ GWMS.API/Startup.cs | 59 +++++++++++++++++++ GWMS.API/WeatherForecast.cs | 15 +++++ GWMS.API/appsettings.Development.json | 9 +++ GWMS.API/appsettings.json | 10 ++++ 8 files changed, 200 insertions(+) create mode 100644 GWMS.API/Controllers/WeatherForecastController.cs create mode 100644 GWMS.API/GWMS.API.csproj create mode 100644 GWMS.API/Program.cs create mode 100644 GWMS.API/Properties/launchSettings.json create mode 100644 GWMS.API/Startup.cs create mode 100644 GWMS.API/WeatherForecast.cs create mode 100644 GWMS.API/appsettings.Development.json create mode 100644 GWMS.API/appsettings.json diff --git a/GWMS.API/Controllers/WeatherForecastController.cs b/GWMS.API/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..1cb32b6 --- /dev/null +++ b/GWMS.API/Controllers/WeatherForecastController.cs @@ -0,0 +1,39 @@ +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace GWMS.API.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] + public IEnumerable Get() + { + var rng = new Random(); + return Enumerable.Range(1, 5).Select(index => new WeatherForecast + { + Date = DateTime.Now.AddDays(index), + TemperatureC = rng.Next(-20, 55), + Summary = Summaries[rng.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} diff --git a/GWMS.API/GWMS.API.csproj b/GWMS.API/GWMS.API.csproj new file mode 100644 index 0000000..2884716 --- /dev/null +++ b/GWMS.API/GWMS.API.csproj @@ -0,0 +1,11 @@ + + + + net5.0 + + + + + + + diff --git a/GWMS.API/Program.cs b/GWMS.API/Program.cs new file mode 100644 index 0000000..26bd302 --- /dev/null +++ b/GWMS.API/Program.cs @@ -0,0 +1,26 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace GWMS.API +{ + public class Program + { + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.UseStartup(); + }); + } +} diff --git a/GWMS.API/Properties/launchSettings.json b/GWMS.API/Properties/launchSettings.json new file mode 100644 index 0000000..48dfb52 --- /dev/null +++ b/GWMS.API/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:31282", + "sslPort": 44346 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "GWMS.API": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/GWMS.API/Startup.cs b/GWMS.API/Startup.cs new file mode 100644 index 0000000..6b4f0ce --- /dev/null +++ b/GWMS.API/Startup.cs @@ -0,0 +1,59 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.HttpsPolicy; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.Extensions.Logging; +using Microsoft.OpenApi.Models; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace GWMS.API +{ + public class Startup + { + public Startup(IConfiguration configuration) + { + Configuration = configuration; + } + + public IConfiguration Configuration { get; } + + // This method gets called by the runtime. Use this method to add services to the container. + public void ConfigureServices(IServiceCollection services) + { + + services.AddControllers(); + services.AddSwaggerGen(c => + { + c.SwaggerDoc("v1", new OpenApiInfo { Title = "GWMS.API", Version = "v1" }); + }); + } + + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) + { + if (env.IsDevelopment()) + { + app.UseDeveloperExceptionPage(); + app.UseSwagger(); + app.UseSwaggerUI(c => c.SwaggerEndpoint("/swagger/v1/swagger.json", "GWMS.API v1")); + } + + app.UseHttpsRedirection(); + + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/GWMS.API/WeatherForecast.cs b/GWMS.API/WeatherForecast.cs new file mode 100644 index 0000000..57203b1 --- /dev/null +++ b/GWMS.API/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace GWMS.API +{ + public class WeatherForecast + { + public DateTime Date { get; set; } + + public int TemperatureC { get; set; } + + public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); + + public string Summary { get; set; } + } +} diff --git a/GWMS.API/appsettings.Development.json b/GWMS.API/appsettings.Development.json new file mode 100644 index 0000000..8983e0f --- /dev/null +++ b/GWMS.API/appsettings.Development.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + } +} diff --git a/GWMS.API/appsettings.json b/GWMS.API/appsettings.json new file mode 100644 index 0000000..d9d9a9b --- /dev/null +++ b/GWMS.API/appsettings.json @@ -0,0 +1,10 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +}