From 648d50c387e7ee3976bd673594ed10901075475f Mon Sep 17 00:00:00 2001 From: transtrike Date: Mon, 7 Dec 2020 22:39:49 +0200 Subject: API folder fixed --- API | 1 - API/API.csproj | 14 ++++++++ API/Controllers/WeatherForecastController.cs | 38 +++++++++++++++++++++ API/Program.cs | 24 +++++++++++++ API/Properties/launchSettings.json | 31 +++++++++++++++++ API/Startup.cs | 51 ++++++++++++++++++++++++++++ API/WeatherForecast.cs | 15 ++++++++ API/appsettings.json | 13 +++++++ 8 files changed, 186 insertions(+), 1 deletion(-) delete mode 160000 API create mode 100644 API/API.csproj create mode 100644 API/Controllers/WeatherForecastController.cs create mode 100644 API/Program.cs create mode 100644 API/Properties/launchSettings.json create mode 100644 API/Startup.cs create mode 100644 API/WeatherForecast.cs create mode 100644 API/appsettings.json (limited to 'API') diff --git a/API b/API deleted file mode 160000 index 39ab24d..0000000 --- a/API +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 39ab24dfa14dbb97dfc3348e30d818365d6607fd diff --git a/API/API.csproj b/API/API.csproj new file mode 100644 index 0000000..dcc653c --- /dev/null +++ b/API/API.csproj @@ -0,0 +1,14 @@ + + + + net5.0 + API + + + + + + + + + diff --git a/API/Controllers/WeatherForecastController.cs b/API/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..2e4b29d --- /dev/null +++ b/API/Controllers/WeatherForecastController.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; + +namespace 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/API/Program.cs b/API/Program.cs new file mode 100644 index 0000000..8125904 --- /dev/null +++ b/API/Program.cs @@ -0,0 +1,24 @@ +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Hosting; + +namespace API +{ + public class Program + { + private const int HTTPS_PORT = 5020; + + public static void Main(string[] args) + { + CreateHostBuilder(args).Build().Run(); + } + + public static IHostBuilder CreateHostBuilder(string[] args) => + Host.CreateDefaultBuilder(args) + .ConfigureWebHostDefaults(webBuilder => + { + webBuilder.ConfigureKestrel(opt => opt.ListenLocalhost(HTTPS_PORT)); + + webBuilder.UseStartup(); + }); + } +} diff --git a/API/Properties/launchSettings.json b/API/Properties/launchSettings.json new file mode 100644 index 0000000..939e23e --- /dev/null +++ b/API/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "http://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:31454", + "sslPort": 44373 + } + }, + "profiles": { + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "API": { + "commandName": "Project", + "dotnetRunMessages": "true", + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:5001;http://localhost:5000", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/API/Startup.cs b/API/Startup.cs new file mode 100644 index 0000000..cd2c39a --- /dev/null +++ b/API/Startup.cs @@ -0,0 +1,51 @@ +using Microsoft.AspNetCore.Builder; +using Microsoft.AspNetCore.Hosting; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; +using Microsoft.OpenApi.Models; + +namespace 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 = "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", "API v1")); + } + + app.UseHttpsRedirection(); + app.UseRouting(); + + app.UseAuthorization(); + + app.UseEndpoints(endpoints => + { + endpoints.MapControllers(); + }); + } + } +} diff --git a/API/WeatherForecast.cs b/API/WeatherForecast.cs new file mode 100644 index 0000000..746c136 --- /dev/null +++ b/API/WeatherForecast.cs @@ -0,0 +1,15 @@ +using System; + +namespace 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/API/appsettings.json b/API/appsettings.json new file mode 100644 index 0000000..b13eb27 --- /dev/null +++ b/API/appsettings.json @@ -0,0 +1,13 @@ +{ + "ConnectionString" : { + "DEV": "Server=localhost;Port=5432;Database=API;User Id=postgres;Password=;" + }, + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft": "Warning", + "Microsoft.Hosting.Lifetime": "Information" + } + }, + "AllowedHosts": "*" +} -- cgit v1.2.3