From f37063b548945e1bf81be36aebcd079e9393e2cb Mon Sep 17 00:00:00 2001 From: Thomas Chazot Date: Thu, 2 Feb 2023 18:13:24 +0100 Subject: [PATCH] Ajout des controllers (endpoints) --- .../Sources/ApiLol/ApiLol.csproj | 2 +- .../Sources/ApiLol/ChampionDTO.cs | 15 +++ .../ApiLol/Controllers/ChampionController.cs | 98 ++++++++++++++++++ .../Controllers/WeatherForecastController.cs | 2 +- .../Sources/ConsoleApi/ConsoleApi.csproj | 16 +++ .../Sources/ConsoleApi/Program.cs | 12 +++ .../Sources/ConsoleDb/oiseaux.db | Bin 20480 -> 20480 bytes .../Sources/LeagueOfLegends.sln | 6 ++ 8 files changed, 149 insertions(+), 2 deletions(-) create mode 100644 EntityFramework_LoL/Sources/ApiLol/ChampionDTO.cs create mode 100644 EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionController.cs create mode 100644 EntityFramework_LoL/Sources/ConsoleApi/ConsoleApi.csproj create mode 100644 EntityFramework_LoL/Sources/ConsoleApi/Program.cs diff --git a/EntityFramework_LoL/Sources/ApiLol/ApiLol.csproj b/EntityFramework_LoL/Sources/ApiLol/ApiLol.csproj index 4289e82..8cb33cf 100644 --- a/EntityFramework_LoL/Sources/ApiLol/ApiLol.csproj +++ b/EntityFramework_LoL/Sources/ApiLol/ApiLol.csproj @@ -7,7 +7,7 @@ - + diff --git a/EntityFramework_LoL/Sources/ApiLol/ChampionDTO.cs b/EntityFramework_LoL/Sources/ApiLol/ChampionDTO.cs new file mode 100644 index 0000000..0038870 --- /dev/null +++ b/EntityFramework_LoL/Sources/ApiLol/ChampionDTO.cs @@ -0,0 +1,15 @@ +using System; +namespace ApiLol +{ + public class ChampionDTO + { + public int Id { get; set; } + + public string Name { get; set; } + + public string Icon { get; set; } + + public string Bio { get; set; } + } +} + diff --git a/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionController.cs b/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionController.cs new file mode 100644 index 0000000..ae2d93c --- /dev/null +++ b/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionController.cs @@ -0,0 +1,98 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Microsoft.AspNetCore.Mvc; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace ApiLol.Controllers +{ + [Route("api/[controller]")] + public class ChampionController : ControllerBase + { + private readonly ILogger _logger; + + public ChampionController(ILogger logger) + { + _logger = logger; + } + + + // GET: api/champion + [HttpGet] + public ActionResult> Get() + { + List champions = new List(); + champions.Add(new ChampionDTO + { + Id = 1, + Name = "Aurel", + Bio = "Trop joli", + Icon = "Moi" + }); + champions.Add(new ChampionDTO + { + Id = 2, + Name = "Mathilde", + Bio = "Elle est reloue", + Icon = "Macheval" + }); + return Ok(champions); + } + + // GET api/values/5 + [HttpGet("{id}")] + public ActionResult Get(int id) + { + List champions = new List(); + champions.Add(new ChampionDTO + { + Id = 1, + Name = "Aurel", + Bio = "Trop joli", + Icon = "Moi" + }); + champions.Add(new ChampionDTO + { + Id = 2, + Name = "Mathilde", + Bio = "Elle est reloue", + Icon = "Macheval" + }); + + ChampionDTO? champion = champions.SingleOrDefault((ChampionDTO arg) => arg.Id == id); + if (champion == null) + { + return BadRequest(); + } + return Ok(champion); + } + + // POST api/values + [HttpPost] + public void Post([FromBody]int id, string name, string bio, string icon) + { + if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(bio) || string.IsNullOrWhiteSpace(icon)){ + BadRequest(); + } + else + { + Ok(); + } + } + + // PUT api/values/5 + [HttpPut("{id}")] + public void Put(int id, [FromBody]string value) + { + } + + // DELETE api/values/5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} + diff --git a/EntityFramework_LoL/Sources/ApiLol/Controllers/WeatherForecastController.cs b/EntityFramework_LoL/Sources/ApiLol/Controllers/WeatherForecastController.cs index d460f12..bc367ba 100644 --- a/EntityFramework_LoL/Sources/ApiLol/Controllers/WeatherForecastController.cs +++ b/EntityFramework_LoL/Sources/ApiLol/Controllers/WeatherForecastController.cs @@ -19,7 +19,7 @@ public class WeatherForecastController : ControllerBase } [HttpGet(Name = "GetWeatherForecast")] - public IEnumerable Get() + public IEnumerable Get() { return Enumerable.Range(1, 5).Select(index => new WeatherForecast { diff --git a/EntityFramework_LoL/Sources/ConsoleApi/ConsoleApi.csproj b/EntityFramework_LoL/Sources/ConsoleApi/ConsoleApi.csproj new file mode 100644 index 0000000..68e39d2 --- /dev/null +++ b/EntityFramework_LoL/Sources/ConsoleApi/ConsoleApi.csproj @@ -0,0 +1,16 @@ + + + + Exe + net6.0 + enable + enable + + + + + + + + + diff --git a/EntityFramework_LoL/Sources/ConsoleApi/Program.cs b/EntityFramework_LoL/Sources/ConsoleApi/Program.cs new file mode 100644 index 0000000..341d42d --- /dev/null +++ b/EntityFramework_LoL/Sources/ConsoleApi/Program.cs @@ -0,0 +1,12 @@ +// See https://aka.ms/new-console-template for more information +using static System.Net.WebRequestMethods; + + +HttpClient http = new HttpClient(); +//http.BaseAddress = new Uri("https://localhost:7006/"); + +//Console.WriteLine(await http.GetStringAsync("https://localhost:7006/api/Champion")); +Console.WriteLine(await http.GetStringAsync("https://localhost:7006/api/Champion/1")); + + + diff --git a/EntityFramework_LoL/Sources/ConsoleDb/oiseaux.db b/EntityFramework_LoL/Sources/ConsoleDb/oiseaux.db index 4e8122351e23cd340fee244c7ddb81206ba21160..d0c9a2e3fd7b14c0e86d27f647d28464f48017d7 100644 GIT binary patch delta 73 zcmZozz}T>WaRZA18zcW~2L9KZ1q~kZ%L_BIF-VFEbL1u#C1<4Omu6-rW#;oTFfcIk ce`4VO1XT2bpO1%;S)S85BQduiGe55w001=<%K!iX delta 35 icmZozz}T>WaRZA16NA8JL5GL@6DLTr@iG7boC^T8FbTK- diff --git a/EntityFramework_LoL/Sources/LeagueOfLegends.sln b/EntityFramework_LoL/Sources/LeagueOfLegends.sln index d767722..a425f31 100644 --- a/EntityFramework_LoL/Sources/LeagueOfLegends.sln +++ b/EntityFramework_LoL/Sources/LeagueOfLegends.sln @@ -23,6 +23,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataManagers", "DataManager EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiLol", "ApiLol\ApiLol.csproj", "{51E7E6BF-95E8-4B0E-BB03-330893931C17}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApi", "ConsoleApi\ConsoleApi.csproj", "{A3656054-1143-4235-A511-03CBD3BBCE8E}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -61,6 +63,10 @@ Global {51E7E6BF-95E8-4B0E-BB03-330893931C17}.Debug|Any CPU.Build.0 = Debug|Any CPU {51E7E6BF-95E8-4B0E-BB03-330893931C17}.Release|Any CPU.ActiveCfg = Release|Any CPU {51E7E6BF-95E8-4B0E-BB03-330893931C17}.Release|Any CPU.Build.0 = Release|Any CPU + {A3656054-1143-4235-A511-03CBD3BBCE8E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A3656054-1143-4235-A511-03CBD3BBCE8E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A3656054-1143-4235-A511-03CBD3BBCE8E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A3656054-1143-4235-A511-03CBD3BBCE8E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE