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 1/2] 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); } 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 2/2] 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