📦 ajout de l'attribut Skill pour un champion, la liaison à la bdd n'est pas faite car si on utilise un immutablehashset, il faut pouvoir demander a entity framework d'ignorer une des comparaisons entre hashset et immutablehashset
continuous-integration/drone/push Build is passing Details

pull/11/head
Pierre Ferreira 2 years ago
parent f8fa13a661
commit 7afe310f4e

@ -25,7 +25,7 @@ namespace API_LoL.Controllers
{
var list = await ChampionsManager.GetItems(0,await ChampionsManager.GetNbItems());
if (list.Count() != 0) {
return Ok(list.Select(champion => champion?.toDTO()));
return Ok(list.Select(champion => champion?.ToDTO()));
}else {
return NoContent();
}
@ -49,7 +49,7 @@ namespace API_LoL.Controllers
}
else
{
await ChampionsManager.AddItem(champion.toChampion());
await ChampionsManager.AddItem(champion.ToChampion());
return CreatedAtAction("Post",champion);
}
}

@ -9,15 +9,21 @@ namespace DTO.Mapper
{
public static class ChampionMapper
{
public static ChampionDTO toDTO(this Champion champion)
public static ChampionDTO ToDTO(this Champion champion)
{
return new ChampionDTO(champion.Name, champion.Bio, champion.Icon);
//return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Skills);
}
public static Champion toChampion(this ChampionDTO champion)
public static Champion ToChampion(this ChampionDTO champion)
{
return new Champion(champion.Name, ChampionClass.Unknown, champion.Icon, "", champion.Bio);
Champion champ = new Champion(champion.Name, ChampionClass.Unknown, champion.Icon, "", champion.Bio);
//foreach (Skill skill in champion.Skills)
//{
// champ.AddSkill(skill);
//}
return champ;
}
}
}

@ -2,12 +2,8 @@ using API_LoL.Controllers;
using DTO;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Query;
using Model;
using StubLib;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
namespace Api_UT
{
@ -38,7 +34,7 @@ namespace Api_UT
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon"));
Assert.IsNotNull(a);
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon");
Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value));
//Assert.AreEqual<ChampionDTO>(champ,((CreatedAtActionResult)a).Value);
}
}

@ -1,4 +1,5 @@
using Model;
using System.Collections.Immutable;
namespace DTO
{
@ -11,13 +12,25 @@ namespace DTO
Icon = icon;
}
//public ChampionDTO(string name, string bio, string icon, ICollection<Skill> skills)
//{
// Name = name;
// Bio = bio;
// Icon = icon;
// Skills = skills;
//}
public string Name { get; set; }
public string Bio { get; set; }
//public ChampionClass Class { get; set; }
public string Icon { get; set; }
/// <summary>
/// pour plus tard ?
/// </summary>
//public ImmutableHashSet<Skill> Skills { get; set; }
//public ICollection<Skill> Skills { get; set; }
public bool equals(ChampionDTO other)
{

@ -28,8 +28,10 @@ namespace EntityFramework
[Required]
public string Icon { get; set; }
public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
private HashSet<Skill> skills = new HashSet<Skill>();
//public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
//private HashSet<Skill> skills = new HashSet<Skill>();
private ICollection<Skill> Skills { get; set; }
public ChampionEntity(string name,string bio,string icon) {
this.Name = name;
@ -44,10 +46,10 @@ namespace EntityFramework
public bool AddSkill(Skill skill)
=> skills.Add(skill);
public void AddSkill(Skill skill)
=> this.Skills.Add(skill);
public bool RemoveSkill(Skill skill)
=> skills.Remove(skill);
=> Skills.Remove(skill);
}
}

@ -1,15 +1,18 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace EntityFramework
{
public class Skill
{
public SkillType Type { get; private set; }
[Key]
public string Name
{
get => name;

Loading…
Cancel
Save