From 640e90d92dda2919c11caf0d0e6c2834d07a80be Mon Sep 17 00:00:00 2001 From: "bastien.ollier@etu.uca.fr" Date: Mon, 13 Mar 2023 16:22:38 +0100 Subject: [PATCH] add get dans skin controller --- .../apiLOL/Controllers/ControllerChampions.cs | 2 -- Sources/apiLOL/Controllers/ControllerSkins.cs | 22 +++++++++++++++---- Sources/apiLOL/DTO/ChampionDTO.cs | 1 - Sources/apiLOL/DTO/ChampionMapper.cs | 3 ++- Sources/apiLOL/DTO/SkinDTO.cs | 4 +--- Sources/apiLOL/DTO/SkinMapper.cs | 6 +++-- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/Sources/apiLOL/Controllers/ControllerChampions.cs b/Sources/apiLOL/Controllers/ControllerChampions.cs index 98ff22e..cfc0d31 100644 --- a/Sources/apiLOL/Controllers/ControllerChampions.cs +++ b/Sources/apiLOL/Controllers/ControllerChampions.cs @@ -28,8 +28,6 @@ namespace apiLOL.Controllers [HttpGet] 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 index:{index}, count: {count} et name:{name}"); int nbChampions = await data.ChampionsMgr.GetNbItems(); _logger.LogInformation($"Nombre de champions : {nbChampions}"); diff --git a/Sources/apiLOL/Controllers/ControllerSkins.cs b/Sources/apiLOL/Controllers/ControllerSkins.cs index ee7a408..fdbcaad 100644 --- a/Sources/apiLOL/Controllers/ControllerSkins.cs +++ b/Sources/apiLOL/Controllers/ControllerSkins.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using apiLOL.DTO; +using Microsoft.AspNetCore.Mvc; using Model; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -23,10 +24,23 @@ namespace apiLOL.Controllers // GET api//5 - [HttpGet("{id}")] - public string Get(int id) + [HttpGet] + public async Task Get([FromQuery] int index = 0, int count = 10, string? name = "") { - return "value"; + _logger.LogInformation($"methode Get de ControllerSkins appelée index:{index}, count: {count} et name:{name}"); + int nbSkins = await data.SkinsMgr.GetNbItems(); + _logger.LogInformation($"Nombre de skins : {nbSkins}"); + + var skin = (await data.SkinsMgr.GetItems(index, await data.SkinsMgr.GetNbItems())).Select(Model => Model.ToDTO());//.Where(Model => Model.Name.Contains(name)).Skip(index * count).Take(count).Select(Model => Model.ToDTO()); + + var page = new SkinPageDTO + { + Data = (IEnumerable)skin, + Index = index, + Count = count, + TotalCount = nbSkins + }; + return Ok(page); } // POST api/ diff --git a/Sources/apiLOL/DTO/ChampionDTO.cs b/Sources/apiLOL/DTO/ChampionDTO.cs index 07e0ef2..86cc6c8 100644 --- a/Sources/apiLOL/DTO/ChampionDTO.cs +++ b/Sources/apiLOL/DTO/ChampionDTO.cs @@ -11,7 +11,6 @@ } public string Name { get; set; } - public string Bio { get; set; } public string Icon { get; set; } } diff --git a/Sources/apiLOL/DTO/ChampionMapper.cs b/Sources/apiLOL/DTO/ChampionMapper.cs index 0c92c99..5f767c1 100644 --- a/Sources/apiLOL/DTO/ChampionMapper.cs +++ b/Sources/apiLOL/DTO/ChampionMapper.cs @@ -4,7 +4,8 @@ namespace apiLOL.DTO { public static class ChampionMapper { - public static ChampionDTO ToDTO(this Champion champion) => new ChampionDTO(champion.Name, champion.Bio, champion.Icon); + public static ChampionDTO ToDTO(this Champion champion) + => new ChampionDTO(champion.Name, champion.Bio, champion.Icon); public static Champion ToModel(this ChampionDTO championDTO) diff --git a/Sources/apiLOL/DTO/SkinDTO.cs b/Sources/apiLOL/DTO/SkinDTO.cs index 9955447..01d16a6 100644 --- a/Sources/apiLOL/DTO/SkinDTO.cs +++ b/Sources/apiLOL/DTO/SkinDTO.cs @@ -4,17 +4,15 @@ namespace apiLOL.DTO { public class SkinDTO { - public SkinDTO(string name, Champion champion, float price = 0.0f, string icon = "", string image = "", string description = "") + public SkinDTO(string name, float price = 0.0f, string icon = "", string image = "", string description = "") { Name = name; - Champ = champion; Price = price; Icon = icon; Description = description; } public string Name { get; set; } - public Champion Champ { get; set; } public float Price { get; } public string Icon { get; } public string Description { get; } diff --git a/Sources/apiLOL/DTO/SkinMapper.cs b/Sources/apiLOL/DTO/SkinMapper.cs index d8b4209..19c98a3 100644 --- a/Sources/apiLOL/DTO/SkinMapper.cs +++ b/Sources/apiLOL/DTO/SkinMapper.cs @@ -4,7 +4,9 @@ namespace apiLOL.DTO { public static class SkinMapper { - public static SkinDTO ToDTO(this Skin skin) => new SkinDTO(skin.Name, skin.Champion, skin.Price, skin.Icon, skin.Description); - public static Skin ToModel(this SkinDTO skinDTO) => new Skin(skinDTO.Name, skinDTO.Champ, skinDTO.Price, skinDTO.Icon, "",skinDTO.Description); + public static SkinDTO ToDTO(this Skin skin) + => new SkinDTO(skin.Name, skin.Price, skin.Icon, skin.Description); + public static Skin ToModel(this SkinDTO skinDTO) + => new Skin(skinDTO.Name, null, skinDTO.Price, skinDTO.Icon,"",skinDTO.Description); } }