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