From 8ee7594ec1c6ea3e9e693c566e5092453e7e917f Mon Sep 17 00:00:00 2001 From: Louwar Date: Mon, 30 Jan 2023 16:30:22 +0100 Subject: [PATCH] Add API --- Sources/API/API.csproj | 13 +++++++ .../Controllers/WeatherForecastController.cs | 33 ++++++++++++++++++ Sources/API/Program.cs | 25 +++++++++++++ Sources/API/Properties/launchSettings.json | 31 ++++++++++++++++ Sources/API/WeatherForecast.cs | 13 +++++++ Sources/API/appsettings.Development.json | 8 +++++ Sources/API/appsettings.json | 9 +++++ Sources/EFlib/projet.dbloulou.db-shm | Bin 32768 -> 0 bytes Sources/EFlib/projet.dbloulou.db-wal | 0 Sources/LeagueOfLegends.sln | 8 ++++- 10 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 Sources/API/API.csproj create mode 100644 Sources/API/Controllers/WeatherForecastController.cs create mode 100644 Sources/API/Program.cs create mode 100644 Sources/API/Properties/launchSettings.json create mode 100644 Sources/API/WeatherForecast.cs create mode 100644 Sources/API/appsettings.Development.json create mode 100644 Sources/API/appsettings.json delete mode 100644 Sources/EFlib/projet.dbloulou.db-shm delete mode 100644 Sources/EFlib/projet.dbloulou.db-wal diff --git a/Sources/API/API.csproj b/Sources/API/API.csproj new file mode 100644 index 0000000..60bf9ea --- /dev/null +++ b/Sources/API/API.csproj @@ -0,0 +1,13 @@ + + + + net6.0 + enable + enable + + + + + + + diff --git a/Sources/API/Controllers/WeatherForecastController.cs b/Sources/API/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..4d0175d --- /dev/null +++ b/Sources/API/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +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 = DateTime.Now.AddDays(index), + TemperatureC = Random.Shared.Next(-20, 55), + Summary = Summaries[Random.Shared.Next(Summaries.Length)] + }) + .ToArray(); + } + } +} \ No newline at end of file diff --git a/Sources/API/Program.cs b/Sources/API/Program.cs new file mode 100644 index 0000000..48863a6 --- /dev/null +++ b/Sources/API/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/Sources/API/Properties/launchSettings.json b/Sources/API/Properties/launchSettings.json new file mode 100644 index 0000000..c49b876 --- /dev/null +++ b/Sources/API/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:44020", + "sslPort": 44337 + } + }, + "profiles": { + "API": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7175;http://localhost:5048", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Sources/API/WeatherForecast.cs b/Sources/API/WeatherForecast.cs new file mode 100644 index 0000000..5db3e47 --- /dev/null +++ b/Sources/API/WeatherForecast.cs @@ -0,0 +1,13 @@ +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; } + } +} \ No newline at end of file diff --git a/Sources/API/appsettings.Development.json b/Sources/API/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Sources/API/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Sources/API/appsettings.json b/Sources/API/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Sources/API/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Sources/EFlib/projet.dbloulou.db-shm b/Sources/EFlib/projet.dbloulou.db-shm deleted file mode 100644 index fe9ac2845eca6fe6da8a63cd096d9cf9e24ece10..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 32768 zcmeIuAr62r3