Update propriété
continuous-integration/drone/push Build is failing Details

pull/10/head^2
Louwar 2 years ago
parent 1371e86c20
commit 12457f0a99

@ -57,10 +57,10 @@ namespace API.Controllers
[Route("{id}")] [Route("{id}")]
public async Task<ActionResult<ChampionDto>> GetChampById(int id) public async Task<ActionResult<ChampionDto>> GetChampById(int id)
{ {
BadRequest("404"); // Récupération de la liste des champions
IEnumerable<Champion?> Champs = await data.ChampionsMgr.GetItems(id, 1); IEnumerable<Champion?> Champs = await data.ChampionsMgr.GetItems(id, 1);
// Récupération du champion correspondant à l'id
if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result) if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result)
{ {
return Ok(Champs.First().ToDto()); return Ok(Champs.First().ToDto());
@ -71,23 +71,23 @@ namespace API.Controllers
[HttpGet("{id}/Skins")] [HttpGet("{id}/Skins")]
public async Task<ActionResult<SkinDto>> GetSkinsChamp(int id) public async Task<ActionResult<SkinDto>> GetSkinsChamp(int id)
{ {
// Récupération du champion // Récupération de la liste des champions
IEnumerable<Champion?> ChampNum = await data.ChampionsMgr.GetItems(id, 1); IEnumerable<Champion?> Champs = await data.ChampionsMgr.GetItems(id, 1);
// Récupération du champion correspondant à l'id
if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result) if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result)
{ {
// Converstion en Champion au lieu de champion IEnumerable // Converstion en Champion au lieu de champion IEnumerable
Champion champion = ChampNum.First(); Champion champion = Champs.First();
// Récupération des skin du champion // Récupération des skin du champion
IEnumerable<Skin?> ListeSkin = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result); IEnumerable<Skin?> Skins = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result);
// Création de la liste de skin // Création de la liste de skin
List<SkinDto> skins = new List<SkinDto>(); List<SkinDto> skins = new List<SkinDto>();
// Ajout des skins dans la nouvelle liste // 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); return Ok(skins);
} }
@ -98,23 +98,29 @@ namespace API.Controllers
[HttpPost("Ajouter/{nom}")] [HttpPost("Ajouter/{nom}")]
public async Task<ActionResult> PostChampName(string nom) public async Task<ActionResult> PostChampName(string nom)
{ {
// Création d'un champion avec son nom
Champion champion = new Champion(nom); Champion champion = new Champion(nom);
// Ajout du champion dans la BD
await data.ChampionsMgr.AddItem(champion); await data.ChampionsMgr.AddItem(champion);
return CreatedAtAction(nameof(GetChampById), new { id = data.ChampionsMgr.GetNbItems().Result - 1 }, champion.ToDto()); return CreatedAtAction(nameof(GetChampById), new { id = data.ChampionsMgr.GetNbItems().Result - 1 }, champion.ToDto());
} }
[HttpPost("Ajouter")] [HttpPost("Ajouter")]
public async Task<IActionResult> PostChamp([FromBody] ChampionDto championDto) public async Task<ActionResult> PostChamp([FromBody] ChampionDto championDto)
{ {
// Convertie le championDto en model (a était ajouté via l'API)
Champion champion = championDto.ToModel(); Champion champion = championDto.ToModel();
// Ajout du champion en BD
await data.ChampionsMgr.AddItem(champion); await data.ChampionsMgr.AddItem(champion);
return CreatedAtAction(nameof(data.ChampionsMgr.GetItemsByName), new { Name = championDto.Name }, championDto); return CreatedAtAction(nameof(data.ChampionsMgr.GetItemsByName), new { Name = championDto.Name }, championDto);
} }
[HttpPost] [HttpPost]
public async Task<IActionResult> post([FromBody] ChampionDto championDto) public async Task<ActionResult> post([FromBody] ChampionDto championDto)
{ {
return CreatedAtAction(nameof(GetChampById), new { id = 1 }, return CreatedAtAction(nameof(GetChampById), new { id = 1 },
await data.ChampionsMgr.AddItem(championDto.ToModel())); await data.ChampionsMgr.AddItem(championDto.ToModel()));

@ -17,8 +17,8 @@ namespace API.Dto
public IEnumerable<int> Valuedic { get; set; } public IEnumerable<int> Valuedic { get; set; }
public ChampionClass Class { get; set; } public ChampionClass Class { get; set; }
public ReadOnlyCollection<Skin> Skins { get; set; } public ReadOnlyCollection<SkinDto> Skins { get; set; }
public ImmutableHashSet<EFSkill> Skills { get; private set; } public ImmutableHashSet<SkillDto> Skills { get; private set; }
public LargeImage Image { get; set; } public LargeImage Image { get; set; }
} }

@ -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; }
}
}

@ -5,10 +5,10 @@ namespace API.Dto
public class SkinDto public class SkinDto
{ {
public string Name { get; set; } 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 float Price { get; set; }
public string Icon { get; set; } public string Icon { get; set; }
public LargeImage Image { get; set; } public LargeImage Image { get; set; }
public string Description { get; set; }
} }
} }

@ -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 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, Bio = champion.Bio,
Icon = champion.Icon, Icon = champion.Icon,
Keydic = champion.Characteristics.Keys, Keydic = champion.Characteristics.Keys,
Valuedic = champion.Characteristics.Values, Valuedic = champion.Characteristics.Values,
Class = champion.Class, 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) public static Champion ToModel(this ChampionDto champion)

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

@ -16,11 +16,11 @@ namespace API.Mapping
return new SkinDto() return new SkinDto()
{ {
Name = skin.Name, Name = skin.Name,
Champion = skin.Champion, Champion = skin.Champion.ToDto(),
Description = skin.Description,
Price = skin.Price, Price = skin.Price,
Icon = skin.Icon, Icon = skin.Icon,
Image = skin.Image, Image = skin.Image
Description = skin.Description
}; };
} }
@ -31,7 +31,7 @@ namespace API.Mapping
throw new ArgumentNullException("SkinDto null"); 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);
} }
} }
} }

@ -11,6 +11,6 @@ namespace EFlib
{ {
public string Name { get; set; } public string Name { get; set; }
public string Description { get; set; } public string Description { get; set; }
public SkillType SkillType { get; set; } public SkillType Type { get; set; }
} }
} }

@ -1,13 +1,16 @@
namespace EFlib using Model;
namespace EFlib
{ {
public class EFSkin public class EFSkin
{ {
/**** Attributs ****/ /**** Attributs ****/
public string Name { get; set; } public string Name { get; set; }
public EFChampion champion { get; set; }
public string Description { get; set; } public string Description { get; set; }
public string Icon { get; set; } public string Icon { get; set; }
public float Price { get; set; } public float Price { get; set; }
public EFChampion champion { get; set; } public LargeImage Image { get; set; }
} }
} }

Loading…
Cancel
Save