From 867f3428935c7266929c7b69fe0b64e06d13dbb3 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Thu, 9 Feb 2023 13:38:08 +0100 Subject: [PATCH 01/21] gitignore : add sonarqube --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6c2aa92..5913f3d 100644 --- a/.gitignore +++ b/.gitignore @@ -428,4 +428,5 @@ FodyWeavers.xsd *.sln.iml *.db -*Migrations \ No newline at end of file +*Migrations +*.sonarqube \ No newline at end of file -- 2.36.3 From a446a44976690a1d803c3e5714f485dec206aa92 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Thu, 9 Feb 2023 13:44:22 +0100 Subject: [PATCH 02/21] correction ToModel de champion --- Sources/apiLOL/ChampionMapper.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Sources/apiLOL/ChampionMapper.cs b/Sources/apiLOL/ChampionMapper.cs index 564b52b..35c0e98 100644 --- a/Sources/apiLOL/ChampionMapper.cs +++ b/Sources/apiLOL/ChampionMapper.cs @@ -11,7 +11,9 @@ namespace apiLOL public static Champion ToModel(this ChampionDTO championDTO) { - return new Champion(championDTO.Name); + Champion champ = new Champion(championDTO.Name); + champ.Bio = championDTO.Bio; + return champ; } } -- 2.36.3 From 06b1ae84b04390a1ae52d7be668b82a966816158 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Thu, 9 Feb 2023 13:54:33 +0100 Subject: [PATCH 03/21] Requete POST --- Sources/apiLOL/Controllers/ControllerChampions.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 00e2396..a6581fc 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -42,11 +42,12 @@ namespace apiLOL.Controllers // POST api/ [HttpPost] - public IActionResult Post(ChampionDTO champDTO) + public async Task Post([FromBody] ChampionDTO champDTO) { Champion tmp = champDTO.ToModel(); - data.ChampionsMgr.AddItem(tmp); - return Ok(); + Champion champ = await data.ChampionsMgr.AddItem(tmp); + ChampionDTO dto = champ.ToDTO(); + return CreatedAtAction(nameof(GetChampion), new { name = dto.Name }, dto); } // PUT api//5 -- 2.36.3 From 2f6c475ecdcf8885d0866bcc6506724efc4e6aa7 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Thu, 9 Feb 2023 13:57:19 +0100 Subject: [PATCH 04/21] Test Unitaire POST --- Sources/TestUnitaire/TestAPILol.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Sources/TestUnitaire/TestAPILol.cs b/Sources/TestUnitaire/TestAPILol.cs index 43a6d08..20fc95b 100644 --- a/Sources/TestUnitaire/TestAPILol.cs +++ b/Sources/TestUnitaire/TestAPILol.cs @@ -28,7 +28,6 @@ namespace TestUnitaire Task nbItemTask = nbItem; // Assert - Assert.IsType(result); // Verify that the champions is added to the stub Assert.Equal(7, nbItemTask.Result); -- 2.36.3 From 21109c85e4dd4b560614fe694ce9267c0836a35c Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Thu, 9 Feb 2023 15:15:19 +0100 Subject: [PATCH 05/21] add delete api --- Sources/apiLOL/Controllers/ControllerChampions.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index a6581fc..91d71f2 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -57,9 +57,11 @@ namespace apiLOL.Controllers } // DELETE api//5 - [HttpDelete("{id}")] - public void Delete(int id) + [HttpDelete("{name}")] + public async void Delete(String name) { + var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); + data.ChampionsMgr.DeleteItem(champ); } } -- 2.36.3 From ec9ad445da475eba01cc46513ba6d27bd8518162 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Thu, 9 Feb 2023 15:19:57 +0100 Subject: [PATCH 06/21] Test unitaire : POST + GET --- Sources/TestUnitaire/TestAPILol.cs | 43 +++++++++++++------ .../apiLOL/Controllers/ControllerChampions.cs | 8 ++-- 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/Sources/TestUnitaire/TestAPILol.cs b/Sources/TestUnitaire/TestAPILol.cs index 20fc95b..02dbdee 100644 --- a/Sources/TestUnitaire/TestAPILol.cs +++ b/Sources/TestUnitaire/TestAPILol.cs @@ -7,30 +7,49 @@ namespace TestUnitaire { public class TestAPILol { - [Fact] - public void Test1() + [Theory] + [InlineData("Aatrox", "Aatrox est un champion de League of Legends")] + [InlineData("Ahri", "Ahri est un champion de League of Legends")] + [InlineData("Akali", "Akali est un champion de League of Legends")] + public async Task TestPostChampion(string name, string bio) { + // Arrange + var data = new StubData(); + var controller = new ControllerChampions(new StubData()); + var champDTO = new ChampionDTO(name, bio); + + // Act + var nbInListBefore = data.ChampionsMgr.GetNbItems().Result; + var result = await controller.Post(champDTO); + var nbInListAfter = data.ChampionsMgr.GetNbItems().Result; + // Assert + // IS the champion added to the list, number of champions in the list + 1 + Assert.Equal(nbInListBefore + 1, nbInListAfter); } - [Fact] - public void TestPostChampion() + + [Theory] + [InlineData("Aatrox", "Aatrox est un champion de League of Legends")] + [InlineData("Ahri", "Ahri est un champion de League of Legends")] + [InlineData("Akali", "Akali est un champion de League of Legends")] + public async Task TestGetChampion(string name, string bio) { // Arrange var data = new StubData(); var controller = new ControllerChampions(new StubData()); - var champDTO = new ChampionDTO("Charles", "Charles est un champion de League of Legends"); + var champDTO = new ChampionDTO(name, bio); // Act - var result = controller.Post(champDTO); - data.ChampionsMgr.AddItem(champDTO.ToModel()); - var nbItem = data.ChampionsMgr.GetNbItems(); - Task nbItemTask = nbItem; + // Call method POST to add a champion + var result = await controller.Post(champDTO); + // Call method GET to get the champion + var resultGet = await controller.GetChampion(name); // Assert - // Verify that the champions is added to the stub - Assert.Equal(7, nbItemTask.Result); - + // IS the champion added to the list, number of champions in the list + 1 + Assert.Equal(name, champDTO.Name); + Assert.Equal(bio, champDTO.Bio); } } } \ No newline at end of file diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index a6581fc..91e39b2 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -42,12 +42,12 @@ namespace apiLOL.Controllers // POST api/ [HttpPost] - public async Task Post([FromBody] ChampionDTO champDTO) + public async Task Post(ChampionDTO champDTO) { Champion tmp = champDTO.ToModel(); - Champion champ = await data.ChampionsMgr.AddItem(tmp); - ChampionDTO dto = champ.ToDTO(); - return CreatedAtAction(nameof(GetChampion), new { name = dto.Name }, dto); + Champion champion = await data.ChampionsMgr.AddItem(tmp); + ChampionDTO dtoChamp = champion.ToDTO(); + return CreatedAtAction(nameof(GetChampion), new { name = dtoChamp.Name }, dtoChamp); } // PUT api//5 -- 2.36.3 From e2dec91fd2e1018b064c18ba731ca2c9f298f27e Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Tue, 21 Feb 2023 18:23:09 +0100 Subject: [PATCH 07/21] Add : Log on method of the controller --- Sources/apiLOL/Controllers/ControllerChampions.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 3d6a80b..5911c45 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -12,12 +12,13 @@ namespace apiLOL.Controllers public class ControllerChampions : Controller { private readonly IDataManager data; - - + private readonly ILogger _logger; - public ControllerChampions(IDataManager manager) + + public ControllerChampions(IDataManager manager, ILogger log) { data = manager; + _logger = log; } @@ -25,6 +26,8 @@ namespace apiLOL.Controllers [HttpGet] public async Task Get() { + _logger.LogInformation($"methode Get de ControllerChampions appelée"); + _logger.LogInformation($"Nombre de champions : {await data.ChampionsMgr.GetNbItems()}"); var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); return Ok(champs); } @@ -35,6 +38,7 @@ namespace apiLOL.Controllers [Route("{name}")] public async Task GetChampion(string name) { + _logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}"); var champs = (await data.ChampionsMgr.GetItemsByName(name,0,1)).First(); return Ok(champs.ToDTO()); } @@ -44,6 +48,7 @@ namespace apiLOL.Controllers [HttpPost] public async Task Post(ChampionDTO champDTO) { + _logger.LogInformation($"methode Post de ControllerChampions appelée avec le paramètre {champDTO.Name}"); Champion tmp = champDTO.ToModel(); Champion champion = await data.ChampionsMgr.AddItem(tmp); ChampionDTO dtoChamp = champion.ToDTO(); -- 2.36.3 From 1edff0366aa7902208deae68e2461da02a90ae44 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Tue, 21 Feb 2023 18:32:17 +0100 Subject: [PATCH 08/21] Add example : Filter --- Sources/apiLOL/Controllers/ControllerChampions.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 5911c45..7bc619f 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -24,8 +24,9 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - public async Task Get() + public async Task Get([FromQuery] string name = "") { + //FromQuery permet de filtrer dans la collection de champions en fonction du nom _logger.LogInformation($"methode Get de ControllerChampions appelée"); _logger.LogInformation($"Nombre de champions : {await data.ChampionsMgr.GetNbItems()}"); var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); -- 2.36.3 From 57a6046a0580341ac2b20ea00ca48503bde92266 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Tue, 21 Feb 2023 18:51:33 +0100 Subject: [PATCH 09/21] Add example pagination --- Sources/apiLOL/ChampionPageDTO.cs | 13 +++++++++++++ Sources/apiLOL/Controllers/ControllerChampions.cs | 13 +++++++++++-- 2 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 Sources/apiLOL/ChampionPageDTO.cs diff --git a/Sources/apiLOL/ChampionPageDTO.cs b/Sources/apiLOL/ChampionPageDTO.cs new file mode 100644 index 0000000..5fff791 --- /dev/null +++ b/Sources/apiLOL/ChampionPageDTO.cs @@ -0,0 +1,13 @@ +namespace apiLOL +{ + public class ChampionPageDTO + { + public IEnumerable Data { get; set; } + + public int Index { get; set; } + + public int Count { get; set; } + + public int TotalCount { get; set; } + } +} diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 7bc619f..5e1a255 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -24,13 +24,22 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - public async Task Get([FromQuery] string name = "") + public async Task Get([FromQuery] int index = 0, int count = 10, string name = "") { //FromQuery permet de filtrer dans la collection de champions en fonction du nom _logger.LogInformation($"methode Get de ControllerChampions appelée"); _logger.LogInformation($"Nombre de champions : {await data.ChampionsMgr.GetNbItems()}"); + var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); - return Ok(champs); + + var page = new ChampionPageDTO + { + Data = champs, + Index = index, + Count = count, + TotalCount = 100 + }; + return Ok(page); } -- 2.36.3 From 94f1ec76e632bd0f45303397802a61d7974b878e Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Wed, 22 Feb 2023 15:35:02 +0100 Subject: [PATCH 10/21] Commentaire --- Sources/apiLOL/Controllers/ControllerChampions.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 5e1a255..242abe6 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -27,6 +27,7 @@ namespace apiLOL.Controllers public async Task Get([FromQuery] int index = 0, int count = 10, string name = "") { //FromQuery permet de filtrer dans la collection de champions en fonction du nom + // Possible de faire une classe PageRequest pour gérer les paramètres index et count _logger.LogInformation($"methode Get de ControllerChampions appelée"); _logger.LogInformation($"Nombre de champions : {await data.ChampionsMgr.GetNbItems()}"); -- 2.36.3 From 05ed2809d455b74c7e056a4101c6c21bc97ca8b7 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Wed, 22 Feb 2023 15:49:29 +0100 Subject: [PATCH 11/21] test --- Sources/apiLOL/ChampionDTO.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/apiLOL/ChampionDTO.cs b/Sources/apiLOL/ChampionDTO.cs index 253af0a..f015a14 100644 --- a/Sources/apiLOL/ChampionDTO.cs +++ b/Sources/apiLOL/ChampionDTO.cs @@ -11,6 +11,6 @@ public string Name { get; set; } - public string Bio { get; set; } + public string Bio { get; set; } } } -- 2.36.3 From a2e49a7cde2ea280c4b483a0ce73e5cdaa0ea000 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Wed, 22 Feb 2023 15:53:54 +0100 Subject: [PATCH 12/21] test --- Sources/apiLOL/ChampionMapper.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/apiLOL/ChampionMapper.cs b/Sources/apiLOL/ChampionMapper.cs index 35c0e98..4a27adf 100644 --- a/Sources/apiLOL/ChampionMapper.cs +++ b/Sources/apiLOL/ChampionMapper.cs @@ -14,7 +14,7 @@ namespace apiLOL Champion champ = new Champion(championDTO.Name); champ.Bio = championDTO.Bio; return champ; - } + } } } -- 2.36.3 From c9066e286213394a926af012f99e83a92ecc3940 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Fri, 24 Feb 2023 15:45:17 +0100 Subject: [PATCH 13/21] gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 5913f3d..1132ce9 100644 --- a/.gitignore +++ b/.gitignore @@ -428,5 +428,7 @@ FodyWeavers.xsd *.sln.iml *.db +*.db-shm +*.db-wal *Migrations *.sonarqube \ No newline at end of file -- 2.36.3 From 8caf88020d3b2ba37529ab13ad2dea080d53f131 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 24 Feb 2023 16:04:24 +0100 Subject: [PATCH 14/21] add get avec Pagination --- Sources/apiLOL/Controllers/ControllerChampions.cs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 242abe6..1c36c13 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -24,21 +24,23 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - public async Task Get([FromQuery] int index = 0, int count = 10, string name = "") + public async Task Get(int index = 0, int count = 10) { //FromQuery permet de filtrer dans la collection de champions en fonction du nom // Possible de faire une classe PageRequest pour gérer les paramètres index et count _logger.LogInformation($"methode Get de ControllerChampions appelée"); - _logger.LogInformation($"Nombre de champions : {await data.ChampionsMgr.GetNbItems()}"); - - var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); + int nbChampions = await data.ChampionsMgr.GetNbItems(); + _logger.LogInformation($"Nombre de champions : {nbChampions}"); + + //var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); + var champs = (await data.ChampionsMgr.GetItems(index, count)).Select(Model => Model.ToDTO()); var page = new ChampionPageDTO { Data = champs, Index = index, Count = count, - TotalCount = 100 + TotalCount = nbChampions }; return Ok(page); } -- 2.36.3 From 8331dfec7cab4cea41e4d3053b2008de1015abf9 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 24 Feb 2023 16:14:08 +0100 Subject: [PATCH 15/21] add put bio --- Sources/apiLOL/Controllers/ControllerChampions.cs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 1c36c13..17add29 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -24,7 +24,7 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - public async Task Get(int index = 0, int count = 10) + public async Task Get([FromQuery]int index = 0, int count = 10, string nom="") { //FromQuery permet de filtrer dans la collection de champions en fonction du nom // Possible de faire une classe PageRequest pour gérer les paramètres index et count @@ -32,7 +32,6 @@ namespace apiLOL.Controllers int nbChampions = await data.ChampionsMgr.GetNbItems(); _logger.LogInformation($"Nombre de champions : {nbChampions}"); - //var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO()); var champs = (await data.ChampionsMgr.GetItems(index, count)).Select(Model => Model.ToDTO()); var page = new ChampionPageDTO @@ -69,9 +68,12 @@ namespace apiLOL.Controllers } // PUT api//5 - [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) + [HttpPut("{name}")] + public async Task Put( string name, string bio) { + var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); + champs.Bio = bio; + return Ok(champs.ToDTO()); } // DELETE api//5 -- 2.36.3 From eef6707273ca2b4f2d0f6b3e88eea1eed7227829 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Fri, 24 Feb 2023 16:15:01 +0100 Subject: [PATCH 16/21] Supp weather + versionning sur champions --- .../apiLOL/Controllers/ControllerChampions.cs | 10 ++++-- .../Controllers/WeatherForecastController.cs | 33 ------------------- Sources/apiLOL/WeatherForecast.cs | 13 -------- Sources/apiLOL/apiLOL.csproj | 1 + 4 files changed, 9 insertions(+), 48 deletions(-) delete mode 100644 Sources/apiLOL/Controllers/WeatherForecastController.cs delete mode 100644 Sources/apiLOL/WeatherForecast.cs diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 242abe6..faf99f0 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -8,13 +8,14 @@ using static StubLib.StubData; namespace apiLOL.Controllers { [ApiController] - [Route("api/[controller]")] + [Route("api/v{version:apiVersion}/[controller]")] + [ApiVersion("1.0")] + public class ControllerChampions : Controller { private readonly IDataManager data; private readonly ILogger _logger; - public ControllerChampions(IDataManager manager, ILogger log) { data = manager; @@ -24,6 +25,7 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] + [MapToApiVersion("1.0")] public async Task Get([FromQuery] int index = 0, int count = 10, string name = "") { //FromQuery permet de filtrer dans la collection de champions en fonction du nom @@ -47,6 +49,7 @@ namespace apiLOL.Controllers // GET api//Charle [HttpGet] [Route("{name}")] + [MapToApiVersion("2.0")] public async Task GetChampion(string name) { _logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}"); @@ -57,6 +60,7 @@ namespace apiLOL.Controllers // POST api/ [HttpPost] + [MapToApiVersion("1.0")] public async Task Post(ChampionDTO champDTO) { _logger.LogInformation($"methode Post de ControllerChampions appelée avec le paramètre {champDTO.Name}"); @@ -68,12 +72,14 @@ namespace apiLOL.Controllers // PUT api//5 [HttpPut("{id}")] + [MapToApiVersion("1.0")] public void Put(int id, [FromBody] string value) { } // DELETE api//5 [HttpDelete("{name}")] + [MapToApiVersion("1.0")] public async void Delete(String name) { var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); diff --git a/Sources/apiLOL/Controllers/WeatherForecastController.cs b/Sources/apiLOL/Controllers/WeatherForecastController.cs deleted file mode 100644 index c8e4063..0000000 --- a/Sources/apiLOL/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -namespace apiLOL.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/apiLOL/WeatherForecast.cs b/Sources/apiLOL/WeatherForecast.cs deleted file mode 100644 index e380cd6..0000000 --- a/Sources/apiLOL/WeatherForecast.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace apiLOL -{ - 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/apiLOL/apiLOL.csproj b/Sources/apiLOL/apiLOL.csproj index 82733d5..b90f766 100644 --- a/Sources/apiLOL/apiLOL.csproj +++ b/Sources/apiLOL/apiLOL.csproj @@ -7,6 +7,7 @@ + -- 2.36.3 From 94c54499bf9be11efbb44a3e0ce6e86c7bcaa105 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 24 Feb 2023 16:18:57 +0100 Subject: [PATCH 17/21] add log to put --- Sources/apiLOL/Controllers/ControllerChampions.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 17add29..1feacd7 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -71,6 +71,8 @@ namespace apiLOL.Controllers [HttpPut("{name}")] public async Task Put( string name, string bio) { + _logger.LogInformation($"methode Put de ControllerChampions appelée avec le paramètre name: {name} et bio: {bio}"); + var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); champs.Bio = bio; return Ok(champs.ToDTO()); -- 2.36.3 From 050c8461f26fa966b6929bdbfb4ea6d5ba2b131a Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Fri, 24 Feb 2023 16:23:28 +0100 Subject: [PATCH 18/21] versionning --- Sources/apiLOL/Controllers/ControllerChampions.cs | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 93d2270..dcd6754 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -1,14 +1,11 @@ using Microsoft.AspNetCore.Mvc; using Model; -using StubLib; -using System.Xml.Linq; -using static StubLib.StubData; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace apiLOL.Controllers { [ApiController] - [Route("api/v{version:apiVersion}/[controller]")] + [Route("api/v1/[controller]")] [ApiVersion("1.0")] public class ControllerChampions : Controller @@ -25,7 +22,6 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - [MapToApiVersion("1.0")] public async Task Get([FromQuery] int index = 0, int count = 10, string name = "") { //FromQuery permet de filtrer dans la collection de champions en fonction du nom @@ -50,7 +46,6 @@ namespace apiLOL.Controllers // GET api//Charle [HttpGet] [Route("{name}")] - [MapToApiVersion("2.0")] public async Task GetChampion(string name) { _logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}"); @@ -61,7 +56,6 @@ namespace apiLOL.Controllers // POST api/ [HttpPost] - [MapToApiVersion("1.0")] public async Task Post(ChampionDTO champDTO) { _logger.LogInformation($"methode Post de ControllerChampions appelée avec le paramètre {champDTO.Name}"); @@ -73,7 +67,6 @@ namespace apiLOL.Controllers // PUT api//5 [HttpPut("{name}")] - [MapToApiVersion("1.0")] public async Task Put(string name, string bio) { var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); @@ -83,7 +76,6 @@ namespace apiLOL.Controllers // DELETE api//5 [HttpDelete("{name}")] - [MapToApiVersion("1.0")] public async void Delete(String name) { var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); -- 2.36.3 From 55e062847e2beebcaf0069e2e2d88328cc7e4d60 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 24 Feb 2023 16:58:37 +0100 Subject: [PATCH 19/21] add test des parametre de l'api --- .../apiLOL/Controllers/ControllerChampions.cs | 40 ++++++++++++++----- 1 file changed, 31 insertions(+), 9 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 1feacd7..5be9b16 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -24,7 +24,7 @@ namespace apiLOL.Controllers // GET: api/ [HttpGet] - public async Task Get([FromQuery]int index = 0, int count = 10, string nom="") + public async Task Get([FromQuery]int index = 0, int count = 10) { //FromQuery permet de filtrer dans la collection de champions en fonction du nom // Possible de faire une classe PageRequest pour gérer les paramètres index et count @@ -51,8 +51,15 @@ namespace apiLOL.Controllers public async Task GetChampion(string name) { _logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}"); - var champs = (await data.ChampionsMgr.GetItemsByName(name,0,1)).First(); - return Ok(champs.ToDTO()); + try + { + var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)); + return Ok(champs.First().ToDTO()); + } + catch + { + return BadRequest("erreur de nom de champion"); + } } @@ -73,17 +80,32 @@ namespace apiLOL.Controllers { _logger.LogInformation($"methode Put de ControllerChampions appelée avec le paramètre name: {name} et bio: {bio}"); - var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); - champs.Bio = bio; - return Ok(champs.ToDTO()); + try + { + var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); + champs.Bio = bio; + return Ok(champs.ToDTO()); + } + catch + { + return BadRequest("erreur de nom de champion"); + } } // DELETE api//5 [HttpDelete("{name}")] - public async void Delete(String name) + public async Task Delete(String name) { - var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); - data.ChampionsMgr.DeleteItem(champ); + try + { + var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First(); + data.ChampionsMgr.DeleteItem(champ); + return Ok(champ.ToDTO()); + } + catch + { + return BadRequest("erreur de nom de champion"); + } } } -- 2.36.3 From cce59a0adfb3a3d99c5ed2d92d5eaa9e9be47fc9 Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Fri, 24 Feb 2023 17:06:53 +0100 Subject: [PATCH 20/21] modif mapper --- Sources/apiLOL/ChampionMapper.cs | 6 ++---- .../apiLOL/Controllers/ControllerChampions.cs | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Sources/apiLOL/ChampionMapper.cs b/Sources/apiLOL/ChampionMapper.cs index 4a27adf..a7009ab 100644 --- a/Sources/apiLOL/ChampionMapper.cs +++ b/Sources/apiLOL/ChampionMapper.cs @@ -4,10 +4,8 @@ namespace apiLOL { public static class ChampionMapper { - public static ChampionDTO ToDTO(this Champion champion) - { - return new ChampionDTO(champion.Name, champion.Bio); - } + public static ChampionDTO ToDTO(this Champion champion) => new ChampionDTO(champion.Name, champion.Bio); + public static Champion ToModel(this ChampionDTO championDTO) { diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 8243e03..18bb600 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -66,10 +66,19 @@ namespace apiLOL.Controllers public async Task Post(ChampionDTO champDTO) { _logger.LogInformation($"methode Post de ControllerChampions appelée avec le paramètre {champDTO.Name}"); - Champion tmp = champDTO.ToModel(); - Champion champion = await data.ChampionsMgr.AddItem(tmp); - ChampionDTO dtoChamp = champion.ToDTO(); - return CreatedAtAction(nameof(GetChampion), new { name = dtoChamp.Name }, dtoChamp); + + + try + { + Champion tmp = champDTO.ToModel(); + Champion champion = await data.ChampionsMgr.AddItem(tmp); + ChampionDTO dtoChamp = champion.ToDTO(); + return CreatedAtAction(nameof(GetChampion), new { name = dtoChamp.Name }, dtoChamp); + } + catch + { + return BadRequest("le champion existe deja"); + } } // PUT api//5 -- 2.36.3 From 019c8366b02e7b277997660b8e83a6bf157138e7 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Fri, 24 Feb 2023 17:09:03 +0100 Subject: [PATCH 21/21] Modif test unitaire --- Sources/TestUnitaire/TestAPILol.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Sources/TestUnitaire/TestAPILol.cs b/Sources/TestUnitaire/TestAPILol.cs index 02dbdee..e819972 100644 --- a/Sources/TestUnitaire/TestAPILol.cs +++ b/Sources/TestUnitaire/TestAPILol.cs @@ -1,6 +1,8 @@ using apiLOL; using apiLOL.Controllers; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging; +using Microsoft.Extensions.Logging.Abstractions; using StubLib; namespace TestUnitaire @@ -8,14 +10,15 @@ namespace TestUnitaire public class TestAPILol { [Theory] - [InlineData("Aatrox", "Aatrox est un champion de League of Legends")] - [InlineData("Ahri", "Ahri est un champion de League of Legends")] - [InlineData("Akali", "Akali est un champion de League of Legends")] + [InlineData("Beatrice", "sdfsdfd")] + [InlineData("Maurice", "Ahri est un champion de League of Legends")] + [InlineData("Loupiotte", "Akali est un champion de League of Legends")] public async Task TestPostChampion(string name, string bio) { // Arrange var data = new StubData(); - var controller = new ControllerChampions(new StubData()); + var logger = new NullLogger(); + var controller = new ControllerChampions(data, logger); var champDTO = new ChampionDTO(name, bio); // Act @@ -30,14 +33,15 @@ namespace TestUnitaire [Theory] - [InlineData("Aatrox", "Aatrox est un champion de League of Legends")] - [InlineData("Ahri", "Ahri est un champion de League of Legends")] - [InlineData("Akali", "Akali est un champion de League of Legends")] + [InlineData("Beatrice", "Aatrox est un champion de League of Legends")] + [InlineData("Maurice", "Ahri est un champion de League of Legends")] + [InlineData("Loupiotte", "Akali est un champion de League of Legends")] public async Task TestGetChampion(string name, string bio) { // Arrange var data = new StubData(); - var controller = new ControllerChampions(new StubData()); + var logger = new NullLogger(); + var controller = new ControllerChampions(data, logger); var champDTO = new ChampionDTO(name, bio); // Act -- 2.36.3