From 57a6046a0580341ac2b20ea00ca48503bde92266 Mon Sep 17 00:00:00 2001 From: nathan boileau Date: Tue, 21 Feb 2023 18:51:33 +0100 Subject: [PATCH] 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); }