From c6f6341235b27e24a6d00f0cec43330a1e9f302c Mon Sep 17 00:00:00 2001 From: Jolys Enzo Date: Fri, 27 Jan 2023 15:32:43 +0100 Subject: [PATCH] first --- Sources/Api-lol/Api-lol.csproj | 20 +++++++ Sources/Api-lol/Controllers/Champions.cs | 54 +++++++++++++++++++ .../Controllers/WeatherForecastController.cs | 33 ++++++++++++ Sources/Api-lol/Factories/FactoChampions.cs | 19 +++++++ Sources/Api-lol/Program.cs | 30 +++++++++++ .../Api-lol/Properties/launchSettings.json | 31 +++++++++++ Sources/Api-lol/WeatherForecast.cs | 13 +++++ Sources/Api-lol/appsettings.Development.json | 8 +++ Sources/Api-lol/appsettings.json | 9 ++++ Sources/DTO/Class1.cs | 7 +++ Sources/DTO/DTO.csproj | 9 ++++ Sources/DTO/DtoChampions.cs | 18 +++++++ Sources/LeagueOfLegends.sln | 30 +++++++---- 13 files changed, 272 insertions(+), 9 deletions(-) create mode 100644 Sources/Api-lol/Api-lol.csproj create mode 100644 Sources/Api-lol/Controllers/Champions.cs create mode 100644 Sources/Api-lol/Controllers/WeatherForecastController.cs create mode 100644 Sources/Api-lol/Factories/FactoChampions.cs create mode 100644 Sources/Api-lol/Program.cs create mode 100644 Sources/Api-lol/Properties/launchSettings.json create mode 100644 Sources/Api-lol/WeatherForecast.cs create mode 100644 Sources/Api-lol/appsettings.Development.json create mode 100644 Sources/Api-lol/appsettings.json create mode 100644 Sources/DTO/Class1.cs create mode 100644 Sources/DTO/DTO.csproj create mode 100644 Sources/DTO/DtoChampions.cs diff --git a/Sources/Api-lol/Api-lol.csproj b/Sources/Api-lol/Api-lol.csproj new file mode 100644 index 0000000..7aaea74 --- /dev/null +++ b/Sources/Api-lol/Api-lol.csproj @@ -0,0 +1,20 @@ + + + + net6.0 + enable + enable + Api_lol + + + + + + + + + + + + + diff --git a/Sources/Api-lol/Controllers/Champions.cs b/Sources/Api-lol/Controllers/Champions.cs new file mode 100644 index 0000000..991e68b --- /dev/null +++ b/Sources/Api-lol/Controllers/Champions.cs @@ -0,0 +1,54 @@ +using Api_lol.Factories; +using DTO; +using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Mvc; +using Model; +using StubLib; + +namespace Api_lol.Controllers +{ + [ApiController] + [Route("/Champions")] + public class Champions : Controller + { + private readonly IDataManager data; + + private readonly ILogger _logger; + public Champions(ILogger logger,IDataManager manager) + { + _logger = logger; + data = manager; + } + + + [HttpGet] + public IActionResult Get() + { + return Ok(data.ChampionsMgr.GetItems(0,6)); + } + + [HttpPost] + public IActionResult Post(DtoChampions champHttp) + { + champ.Add(champHttp.DtoToModel()); + return Ok(champ); + } + + + + [HttpGet] + [Route("{name}")] + public IActionResult GetChampion(string name) + { + foreach(var champion in champ) + { + if (champion.Name == name) + { + return Ok(champion); + } + } + return BadRequest("Name incorrect"); + } + + } +} diff --git a/Sources/Api-lol/Controllers/WeatherForecastController.cs b/Sources/Api-lol/Controllers/WeatherForecastController.cs new file mode 100644 index 0000000..3062377 --- /dev/null +++ b/Sources/Api-lol/Controllers/WeatherForecastController.cs @@ -0,0 +1,33 @@ +using Microsoft.AspNetCore.Mvc; + +namespace Api_lol.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-lol/Factories/FactoChampions.cs b/Sources/Api-lol/Factories/FactoChampions.cs new file mode 100644 index 0000000..8d61f11 --- /dev/null +++ b/Sources/Api-lol/Factories/FactoChampions.cs @@ -0,0 +1,19 @@ +using DTO; +using Model; +using System.Runtime.CompilerServices; + +namespace Api_lol.Factories +{ + public static class FactoChampions + { + public static Champion DtoToModel(this DtoChampions champDto) + { + return new Champion(champDto.name); + } + + public static DtoChampions ModelToDto(this Champion champ) + { + return new DtoChampions(champ.Name); + } + } +} diff --git a/Sources/Api-lol/Program.cs b/Sources/Api-lol/Program.cs new file mode 100644 index 0000000..4e7ea07 --- /dev/null +++ b/Sources/Api-lol/Program.cs @@ -0,0 +1,30 @@ +using Model; +using StubLib; + +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(); + +builder.Services.AddSingleton(); + +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-lol/Properties/launchSettings.json b/Sources/Api-lol/Properties/launchSettings.json new file mode 100644 index 0000000..920d3f6 --- /dev/null +++ b/Sources/Api-lol/Properties/launchSettings.json @@ -0,0 +1,31 @@ +{ + "$schema": "https://json.schemastore.org/launchsettings.json", + "iisSettings": { + "windowsAuthentication": false, + "anonymousAuthentication": true, + "iisExpress": { + "applicationUrl": "http://localhost:64167", + "sslPort": 44356 + } + }, + "profiles": { + "Api_lol": { + "commandName": "Project", + "dotnetRunMessages": true, + "launchBrowser": true, + "launchUrl": "swagger", + "applicationUrl": "https://localhost:7081;http://localhost:5206", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + }, + "IIS Express": { + "commandName": "IISExpress", + "launchBrowser": true, + "launchUrl": "swagger", + "environmentVariables": { + "ASPNETCORE_ENVIRONMENT": "Development" + } + } + } +} diff --git a/Sources/Api-lol/WeatherForecast.cs b/Sources/Api-lol/WeatherForecast.cs new file mode 100644 index 0000000..f17e950 --- /dev/null +++ b/Sources/Api-lol/WeatherForecast.cs @@ -0,0 +1,13 @@ +namespace Api_lol +{ + 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-lol/appsettings.Development.json b/Sources/Api-lol/appsettings.Development.json new file mode 100644 index 0000000..0c208ae --- /dev/null +++ b/Sources/Api-lol/appsettings.Development.json @@ -0,0 +1,8 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + } +} diff --git a/Sources/Api-lol/appsettings.json b/Sources/Api-lol/appsettings.json new file mode 100644 index 0000000..10f68b8 --- /dev/null +++ b/Sources/Api-lol/appsettings.json @@ -0,0 +1,9 @@ +{ + "Logging": { + "LogLevel": { + "Default": "Information", + "Microsoft.AspNetCore": "Warning" + } + }, + "AllowedHosts": "*" +} diff --git a/Sources/DTO/Class1.cs b/Sources/DTO/Class1.cs new file mode 100644 index 0000000..a440c7c --- /dev/null +++ b/Sources/DTO/Class1.cs @@ -0,0 +1,7 @@ +namespace DTO +{ + public class Class1 + { + + } +} \ No newline at end of file diff --git a/Sources/DTO/DTO.csproj b/Sources/DTO/DTO.csproj new file mode 100644 index 0000000..132c02c --- /dev/null +++ b/Sources/DTO/DTO.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/Sources/DTO/DtoChampions.cs b/Sources/DTO/DtoChampions.cs new file mode 100644 index 0000000..70f216a --- /dev/null +++ b/Sources/DTO/DtoChampions.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class DtoChampions + { + public string name; + + public DtoChampions(string name) + { + this.name = name; + } + } +} diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 0ea57ff..9c08cdc 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -1,19 +1,23 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 25.0.1704.2 +# Visual Studio Version 17 +VisualStudioVersion = 17.4.33205.214 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Model", "Model\Model.csproj", "{2960F9BA-49DE-494D-92E3-CE5A794BA1A9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Model", "Model\Model.csproj", "{2960F9BA-49DE-494D-92E3-CE5A794BA1A9}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{C76D0C23-1FFA-4963-93CD-E12BD643F030}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleTests", "Tests\ConsoleTests\ConsoleTests.csproj", "{1889FA6E-B7C6-416E-8628-9449FB9070B9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleTests", "Tests\ConsoleTests\ConsoleTests.csproj", "{1889FA6E-B7C6-416E-8628-9449FB9070B9}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{3B720C0C-53FE-4642-A2DB-87FD8634CD74}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Shared", "Shared\Shared.csproj", "{3B720C0C-53FE-4642-A2DB-87FD8634CD74}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stub", "Stub", "{2C607793-B163-4731-A4D1-AFE8A7C4C170}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubLib", "StubLib\StubLib.csproj", "{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.csproj", "{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Api-lol", "Api-lol\Api-lol.csproj", "{F5586026-FAB8-499F-86E5-197674F775A9}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTO", "DTO\DTO.csproj", "{35D5E576-6E1A-4B2C-8FE6-C9C9B88FC452}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -37,15 +41,23 @@ Global {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}.Debug|Any CPU.Build.0 = Debug|Any CPU {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}.Release|Any CPU.ActiveCfg = Release|Any CPU {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}.Release|Any CPU.Build.0 = Release|Any CPU + {F5586026-FAB8-499F-86E5-197674F775A9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5586026-FAB8-499F-86E5-197674F775A9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5586026-FAB8-499F-86E5-197674F775A9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5586026-FAB8-499F-86E5-197674F775A9}.Release|Any CPU.Build.0 = Release|Any CPU + {35D5E576-6E1A-4B2C-8FE6-C9C9B88FC452}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {35D5E576-6E1A-4B2C-8FE6-C9C9B88FC452}.Debug|Any CPU.Build.0 = Debug|Any CPU + {35D5E576-6E1A-4B2C-8FE6-C9C9B88FC452}.Release|Any CPU.ActiveCfg = Release|Any CPU + {35D5E576-6E1A-4B2C-8FE6-C9C9B88FC452}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection - GlobalSection(ExtensibilityGlobals) = postSolution - SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} - EndGlobalSection GlobalSection(NestedProjects) = preSolution {1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030} {B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170} EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {92F3083D-793F-4552-8A9A-0AD6534159C9} + EndGlobalSection EndGlobal