diff --git a/Sources/API/Controllers/ChampionController.cs b/Sources/API/Controllers/ChampionController.cs index 28f5012..31ee574 100644 --- a/Sources/API/Controllers/ChampionController.cs +++ b/Sources/API/Controllers/ChampionController.cs @@ -57,10 +57,10 @@ namespace API.Controllers [Route("{id}")] public async Task> GetChampById(int id) { - BadRequest("404"); - + // Récupération de la liste des champions IEnumerable Champs = await data.ChampionsMgr.GetItems(id, 1); + // Récupération du champion correspondant à l'id if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result) { return Ok(Champs.First().ToDto()); @@ -71,23 +71,23 @@ namespace API.Controllers [HttpGet("{id}/Skins")] public async Task> GetSkinsChamp(int id) { - // Récupération du champion - IEnumerable ChampNum = await data.ChampionsMgr.GetItems(id, 1); - + // Récupération de la liste des champions + IEnumerable Champs = await data.ChampionsMgr.GetItems(id, 1); + // Récupération du champion correspondant à l'id if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result) { // Converstion en Champion au lieu de champion IEnumerable - Champion champion = ChampNum.First(); + Champion champion = Champs.First(); // Récupération des skin du champion - IEnumerable ListeSkin = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result); + IEnumerable Skins = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result); // Création de la liste de skin List skins = new List(); - + // Ajout des skins dans la nouvelle liste - ListeSkin.ToList().ForEach(Skin => skins.Add(Skin.ToDto())); + Skins.ToList().ForEach(Skin => skins.Add(Skin.ToDto())); return Ok(skins); } @@ -98,23 +98,29 @@ namespace API.Controllers [HttpPost("Ajouter/{nom}")] public async Task PostChampName(string nom) { + // Création d'un champion avec son nom Champion champion = new Champion(nom); + // Ajout du champion dans la BD await data.ChampionsMgr.AddItem(champion); return CreatedAtAction(nameof(GetChampById), new { id = data.ChampionsMgr.GetNbItems().Result - 1 }, champion.ToDto()); } [HttpPost("Ajouter")] - public async Task PostChamp([FromBody] ChampionDto championDto) + public async Task PostChamp([FromBody] ChampionDto championDto) { + // Convertie le championDto en model (a était ajouté via l'API) Champion champion = championDto.ToModel(); + + // Ajout du champion en BD await data.ChampionsMgr.AddItem(champion); + return CreatedAtAction(nameof(data.ChampionsMgr.GetItemsByName), new { Name = championDto.Name }, championDto); } [HttpPost] - public async Task post([FromBody] ChampionDto championDto) + public async Task post([FromBody] ChampionDto championDto) { return CreatedAtAction(nameof(GetChampById), new { id = 1 }, await data.ChampionsMgr.AddItem(championDto.ToModel())); diff --git a/Sources/API/Dto/ChampionDto.cs b/Sources/API/Dto/ChampionDto.cs index 60f6fe5..e09dfa5 100644 --- a/Sources/API/Dto/ChampionDto.cs +++ b/Sources/API/Dto/ChampionDto.cs @@ -17,8 +17,8 @@ namespace API.Dto public IEnumerable Valuedic { get; set; } public ChampionClass Class { get; set; } - public ReadOnlyCollection Skins { get; set; } - public ImmutableHashSet Skills { get; private set; } + public ReadOnlyCollection Skins { get; set; } + public ImmutableHashSet Skills { get; private set; } public LargeImage Image { get; set; } } diff --git a/Sources/API/Dto/SkillDto.cs b/Sources/API/Dto/SkillDto.cs new file mode 100644 index 0000000..25757bf --- /dev/null +++ b/Sources/API/Dto/SkillDto.cs @@ -0,0 +1,11 @@ +using Model; + +namespace API.Dto +{ + public class SkillDto + { + public string Name { get; set; } + public string Description { get; set; } + public SkillType Type { get; set; } + } +} diff --git a/Sources/API/Dto/SkinDto.cs b/Sources/API/Dto/SkinDto.cs index 9e9f6d0..f4ebc41 100644 --- a/Sources/API/Dto/SkinDto.cs +++ b/Sources/API/Dto/SkinDto.cs @@ -5,10 +5,10 @@ namespace API.Dto public class SkinDto { public string Name { get; set; } - public Champion Champion { get; set; } + public ChampionDto Champion { get; set; } + public string Description { get; set; } public float Price { get; set; } public string Icon { get; set; } public LargeImage Image { get; set; } - public string Description { get; set; } } } diff --git a/Sources/API/Mapping/ChampionMapper.cs b/Sources/API/Mapping/ChampionMapper.cs index c1ad840..6cfafdb 100644 --- a/Sources/API/Mapping/ChampionMapper.cs +++ b/Sources/API/Mapping/ChampionMapper.cs @@ -21,11 +21,14 @@ namespace API.Mapping Name = champion.Name, // je peux décider de mettre le nom en minuscule pour que le json est des noms en minuscule Bio = champion.Bio, Icon = champion.Icon, + Keydic = champion.Characteristics.Keys, Valuedic = champion.Characteristics.Values, + Class = champion.Class, - Image = champion.Image, - Skins = champion.Skins + Skins = champion.Skins, + Skills = champion.Skills, + Image = champion.Image }; } public static Champion ToModel(this ChampionDto champion) diff --git a/Sources/API/Mapping/SkillMapper.cs b/Sources/API/Mapping/SkillMapper.cs new file mode 100644 index 0000000..06be263 --- /dev/null +++ b/Sources/API/Mapping/SkillMapper.cs @@ -0,0 +1,33 @@ +using API.Dto; +using Model; + +namespace API.Mapping +{ + public static class SkillMapper + { + public static SkillDto ToDto(this Skill skill) + { + if (skill == null) + { + throw new ArgumentNullException("Skill null"); + } + + return new SkillDto() + { + Name = skill.Name, + Description = skill.Description, + Type = skill.Type + }; + } + + public static Skill ToSkill(this SkillDto skillDto) + { + if (skillDto == null) + { + throw new ArgumentNullException("SkinDto null"); + } + + return new Skill(skillDto.Name, skillDto.Type, skillDto.Description); + } + } +} diff --git a/Sources/API/Mapping/SkinMapper.cs b/Sources/API/Mapping/SkinMapper.cs index 9ef0014..7066a64 100644 --- a/Sources/API/Mapping/SkinMapper.cs +++ b/Sources/API/Mapping/SkinMapper.cs @@ -16,11 +16,11 @@ namespace API.Mapping return new SkinDto() { Name = skin.Name, - Champion = skin.Champion, + Champion = skin.Champion.ToDto(), + Description = skin.Description, Price = skin.Price, Icon = skin.Icon, - Image = skin.Image, - Description = skin.Description + Image = skin.Image }; } @@ -31,7 +31,7 @@ namespace API.Mapping throw new ArgumentNullException("SkinDto null"); } - return new Skin(skinDto.Name, skinDto.Champion, skinDto.Price, skinDto.Icon, skinDto.Image.Base64, skinDto.Description); + return new Skin(skinDto.Name, skinDto.Champion.ToModel(), skinDto.Price, skinDto.Icon, skinDto.Image.Base64, skinDto.Description); } } } diff --git a/Sources/EFlib/EFSkill.cs b/Sources/EFlib/EFSkill.cs index 7af417f..14ea1fc 100644 --- a/Sources/EFlib/EFSkill.cs +++ b/Sources/EFlib/EFSkill.cs @@ -11,6 +11,6 @@ namespace EFlib { public string Name { get; set; } public string Description { get; set; } - public SkillType SkillType { get; set; } + public SkillType Type { get; set; } } } diff --git a/Sources/EFlib/EFSkin.cs b/Sources/EFlib/EFSkin.cs index 76488da..d42d767 100644 --- a/Sources/EFlib/EFSkin.cs +++ b/Sources/EFlib/EFSkin.cs @@ -1,13 +1,16 @@ -namespace EFlib +using Model; + +namespace EFlib { public class EFSkin { /**** Attributs ****/ public string Name { get; set; } + public EFChampion champion { get; set; } public string Description { get; set; } public string Icon { get; set; } public float Price { get; set; } - public EFChampion champion { get; set; } + public LargeImage Image { get; set; } } }