From f9284d7b792f3c355d5be9c30bddc6d159644bab Mon Sep 17 00:00:00 2001 From: Louis DUFOUR Date: Thu, 23 Mar 2023 20:13:02 +0100 Subject: [PATCH] API Dto & Mapping finit --- Sources/API/Dto/ChampionDto.cs | 2 +- Sources/API/Mapping/ChampionMapper.cs | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Sources/API/Dto/ChampionDto.cs b/Sources/API/Dto/ChampionDto.cs index ae39ad6..a3068a2 100644 --- a/Sources/API/Dto/ChampionDto.cs +++ b/Sources/API/Dto/ChampionDto.cs @@ -18,7 +18,7 @@ namespace API.Dto public ChampionClass Class { get; set; } public ReadOnlyCollection Skins { get; set; } - public ImmutableHashSet Skills { get; private set; } + public ImmutableHashSet Skills { get; set; } public LargeImage Image { get; set; } } diff --git a/Sources/API/Mapping/ChampionMapper.cs b/Sources/API/Mapping/ChampionMapper.cs index 0ea0c6c..99d8fc9 100644 --- a/Sources/API/Mapping/ChampionMapper.cs +++ b/Sources/API/Mapping/ChampionMapper.cs @@ -1,9 +1,7 @@ using API.Dto; using Model; using System.Collections.ObjectModel; -using System.Reflection.PortableExecutable; -using static System.Net.Mime.MediaTypeNames; -using System.Security.Claims; +using System.Collections.Immutable; namespace API.Mapping { @@ -26,8 +24,8 @@ namespace API.Mapping ValueCharac = champion.Characteristics.Values, Class = champion.Class, - Skins = champion.Skins, - Skills = champion.Skills, + Skins = (ReadOnlyCollection)champion.Skins.Select(skin => skin.ToDto()), + Skills = (ImmutableHashSet)champion.Skills.Select(skill => skill.ToDto()), Image = champion.Image }; } @@ -38,8 +36,11 @@ namespace API.Mapping throw new ArgumentNullException("DtoChampion null"); } var champion = new Champion(DtoChamp.Name, DtoChamp.Class, DtoChamp.Icon, DtoChamp.Image.Base64, DtoChamp.Bio); + if (DtoChamp.Skills != null) foreach (var skill in DtoChamp.Skills) { champion.AddSkill(skill.toModel()); } - if (DtoChamp.Characteristics != null) foreach (var charac in DtoChamp.Characteristics) { champion.AddCharacteristics(charac.toModel()); } + + champion.AddCharacteristics((Tuple)DtoChamp.NameCharac.Zip(DtoChamp.ValueCharac, (name, value) => Tuple.Create(name, value))); + return champion; } }