From 5e0e3723b48fcc951e47776251458382b0237be5 Mon Sep 17 00:00:00 2001 From: Stephen Verbist Date: Fri, 7 Jul 2023 18:42:28 +0200 Subject: [PATCH] Base api --- .gitignore | 49 ++++++++++++++++--- plugins.sln | 27 ++++++++++ .../Controllers/WeatherForecastController.cs | 32 ++++++++++++ src/api/Program.cs | 24 +++++++++ src/api/Properties/launchSettings.json | 41 ++++++++++++++++ src/api/WeatherForecast.cs | 12 +++++ src/api/api.csproj | 14 ++++++ src/api/appsettings.Development.json | 8 +++ src/api/appsettings.json | 9 ++++ 9 files changed, 208 insertions(+), 8 deletions(-) create mode 100644 plugins.sln create mode 100644 src/api/Controllers/WeatherForecastController.cs create mode 100644 src/api/Program.cs create mode 100644 src/api/Properties/launchSettings.json create mode 100644 src/api/WeatherForecast.cs create mode 100644 src/api/api.csproj create mode 100644 src/api/appsettings.Development.json create mode 100644 src/api/appsettings.json diff --git a/.gitignore b/.gitignore index 13847c7..bfca666 100644 --- a/.gitignore +++ b/.gitignore @@ -1,10 +1,43 @@ -# ---> MonoDevelop -#User Specific -*.userprefs -*.usertasks +*.swp +*.*~ +project.lock.json +.DS_Store +*.pyc +nupkg/ -#Mono Project Files -*.pidb -*.resources -test-results/ +# Visual Studio Code +.vscode/ +# Rider +.idea/ + +# Visual Studio +.vs/ + +# Fleet +.fleet/ + +# Code Rush +.cr/ + +# User-specific files +*.suo +*.user +*.userosscache +*.sln.docstates + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +[Rr]eleases/ +x64/ +x86/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ +[Oo]ut/ +msbuild.log +msbuild.err +msbuild.wrn diff --git a/plugins.sln b/plugins.sln new file mode 100644 index 0000000..b37d2f2 --- /dev/null +++ b/plugins.sln @@ -0,0 +1,27 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.31903.59 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{9FEC7BBE-4C15-4661-BD19-FC351F4A064E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "api", "src\api\api.csproj", "{1F870768-59EF-4254-ABA9-7E8D25168145}" +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 + {1F870768-59EF-4254-ABA9-7E8D25168145}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F870768-59EF-4254-ABA9-7E8D25168145}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F870768-59EF-4254-ABA9-7E8D25168145}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F870768-59EF-4254-ABA9-7E8D25168145}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(NestedProjects) = preSolution + {1F870768-59EF-4254-ABA9-7E8D25168145} = {9FEC7BBE-4C15-4661-BD19-FC351F4A064E} + EndGlobalSection +EndGlobal diff --git a/src/api/Controllers/WeatherForecastController.cs b/src/api/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..84cdcb8 --- /dev/null +++ b/src/api/Controllers/WeatherForecastController.cs @@ -0,0 +1,32 @@ +using Microsoft.AspNetCore.Mvc; + +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(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/api/Program.cs b/src/api/Program.cs new file mode 100644 index 0000000..f57d866 --- /dev/null +++ b/src/api/Program.cs @@ -0,0 +1,24 @@ +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/api/Properties/launchSettings.json b/src/api/Properties/launchSettings.json new file mode 100644 index 0000000..a8d1745 --- /dev/null +++ b/src/api/Properties/launchSettings.json @@ -0,0 +1,41 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:21232", + "sslPort": 44315 + } + }, + "profiles": { + "http": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "http://localhost:5176", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "https": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7067;http://localhost:5176", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/src/api/WeatherForecast.cs b/src/api/WeatherForecast.cs new file mode 100644 index 0000000..21f189d --- /dev/null +++ b/src/api/WeatherForecast.cs @@ -0,0 +1,12 @@ +namespace 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/src/api/api.csproj b/src/api/api.csproj new file mode 100644 index 0000000..fe46476 --- /dev/null +++ b/src/api/api.csproj @@ -0,0 +1,14 @@ + + + + net7.0 + enable + enable + + + + + + + + diff --git a/src/api/appsettings.Development.json b/src/api/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/src/api/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/src/api/appsettings.json b/src/api/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/src/api/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +}