Merge pull request 'getSkinsById' (#19) from getSkinsById into master
continuous-integration/drone/push Build is passing Details

Reviewed-on: #19
pull/20/head
Corentin RICHARD 2 years ago
commit 9dd133abea

@ -4,6 +4,10 @@ using StubLib;
using DTO;
using DTO.Mapper;
using System.CodeDom.Compiler;
using System.Drawing;
using System;
using API_LoL.Mapper;
using System.Xml.Linq;
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
@ -15,15 +19,17 @@ namespace API_LoL.Controllers
{
public ChampionsController(IDataManager Manager) {
this.ChampionsManager= Manager.ChampionsMgr;
this.ChampionsManager = Manager.ChampionsMgr;
this.SkinsManager = Manager.SkinsMgr;
}
private IChampionsManager ChampionsManager;
private ISkinsManager SkinsManager;
// GET api/<ChampionController>/5
[HttpGet]
public async Task<IActionResult> Get(String? name= null,String? skill = null, String? characteristic = null,int index = 0,int size =10)
public async Task<IActionResult> Get(string? name = null,String? skill = null, String? characteristic = null,int index = 0,int size =10)
{
if (size - index > 10)
{
@ -31,13 +37,14 @@ namespace API_LoL.Controllers
}
if (!string.IsNullOrEmpty(name))
{
var list = await ChampionsManager.GetItemsByName(name, index,size);
var list = await ChampionsManager.GetItemsByName(name, index, size);
if (list.Count() != 0)
{
return Ok(list.Select(champion => champion?.ToDTO()));
}
else { return NoContent(); }
}else if(!string.IsNullOrEmpty(skill)) {
}
else if(!string.IsNullOrEmpty(skill)) {
var list = await ChampionsManager.GetItemsBySkill(skill, index, size);
if (list.Count() != 0)
{
@ -63,8 +70,38 @@ namespace API_LoL.Controllers
}
}
// POST api/<ChampionController>
[HttpPost]
[HttpGet("name")]
public async Task<IActionResult> GetByName(String name)
{
if (string.IsNullOrEmpty(name)) return BadRequest();
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
return Ok(list.Select(champion => champion?.ToDTO()).First());
}
else { return NoContent(); }
}
[HttpGet("name/skins")]
public async Task<IActionResult> GetSkinsByName(String name)
{
if (string.IsNullOrEmpty(name)) return BadRequest();
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, await SkinsManager.GetNbItemsByChampion(list.First()));
if (skins.Count() != 0)
{
return Ok(skins.Select(skin => skin?.ToDTO()));
}
else { return NoContent(); }
}
else { return NoContent(); }
}
// POST api/<ChampionController>
[HttpPost]
public async Task<IActionResult> Post(ChampionDTO champion)
{
if (champion == null)

@ -0,0 +1,34 @@
using DTO;
using Model;
namespace API_LoL.Mapper
{
public static class ChampionClassMapper
{
public static string ToDTO(this ChampionClass championClass)
{
return championClass.ToString();
}
public static ChampionClass ToChampionClass(this String championClass)
{
switch (championClass)
{
case "Assassin":
return ChampionClass.Assassin;
case "Fighter":
return ChampionClass.Fighter;
case "Mage":
return ChampionClass.Mage;
case "Marksman":
return ChampionClass.Marksman;
case "Support":
return ChampionClass.Support;
case "Tank":
return ChampionClass.Tank;
default:
return ChampionClass.Unknown;
}
}
}
}

@ -1,4 +1,5 @@
using Model;
using API_LoL.Mapper;
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
@ -11,13 +12,13 @@ namespace DTO.Mapper
{
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.Class.ToDTO().ToString());
//return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Skills);
}
public static Champion ToChampion(this ChampionDTO champion)
{
Champion champ = new Champion(champion.Name, ChampionClass.Unknown, champion.Icon, "", champion.Bio);
Champion champ = new Champion(champion.Name, champion.Class.ToChampionClass(), champion.Icon, "", champion.Bio);
//foreach (Skill skill in champion.Skills)
//{

@ -0,0 +1,18 @@
using DTO;
using Model;
namespace API_LoL.Mapper
{
public static class SkinMapper
{
public static SkinDTO ToDTO(this Skin skin)
{
return new SkinDTO(skin.Name, skin.Description, skin.Icon);
}
public static Skin ToSkin(this SkinDTO skin)
{
return new Skin(skin.Name, null, icon:skin.Icon) ;
}
}
}

@ -21,7 +21,7 @@ namespace Api_UT
public async Task Get_Default_OkList()
{
List<ChampionDTO> list = new List<ChampionDTO> {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") };
List<ChampionDTO> list = new List<ChampionDTO> {new ChampionDTO("Akali","","","Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter"), new ChampionDTO("Ahri", "", "", "Mage"), new ChampionDTO("Akshan", "", "", "Marksman"), new ChampionDTO("Bard", "", "","Support"), new ChampionDTO("Alistar", "", "","Tank") };
IActionResult a = await api.Get();
a.Should().NotBeNull();
var aObject = a as OkObjectResult;
@ -42,7 +42,7 @@ namespace Api_UT
[TestMethod]
public async Task Get_2First_OkListOf2()
{
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", ""), new ChampionDTO("Aatrox", "", "") };
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter") };
IActionResult a = await api.Get(index: 0,size: 2);
@ -57,7 +57,7 @@ namespace Api_UT
[TestMethod]
public async Task Get_FilterAName_OkListOf5()
{
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", ""), new ChampionDTO("Akshan", "", "") };
List<ChampionDTO> list = new List<ChampionDTO> { new ChampionDTO("Akali", "", "", "Assassin"), new ChampionDTO("Akshan", "", "", "Marksman") };
IActionResult a = await api.Get(name: "Ak");
@ -75,9 +75,9 @@ namespace Api_UT
public async Task Post_ValidChampion_Created()
{
ChampionsController api = new ChampionsController(new StubData());
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon"));
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon", "Assassin"));
Assert.IsNotNull(a);
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon");
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin");
Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value));
}

@ -1,41 +0,0 @@
using API_LoL.Controllers;
using DTO;
using FluentAssertions;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
namespace Api_UT
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public async Task TestGet()
{
List<ChampionDTO> list = new List<ChampionDTO> {new ChampionDTO("Akali","",""), new ChampionDTO("Aatrox", "", ""), new ChampionDTO("Ahri", "", ""), new ChampionDTO("Akshan", "", ""), new ChampionDTO("Bard", "", ""), new ChampionDTO("Alistar", "", "") };
ChampionsController api = new ChampionsController(new StubData());
IActionResult a = await api.Get();
/// utilisation du nuggets fluentAssertion
//Assert.IsNotNull(a);
a.Should().NotBeNull();
//Assert.AreEqual(list,((OkObjectResult)a).Value);
var aObject = a as OkObjectResult;
aObject.Should().NotBeNull();
var championresult = aObject.Value as IEnumerable<ChampionDTO>;
list.Should().BeEquivalentTo(championresult);
}
[TestMethod]
public async Task TestPostValid()
{
ChampionsController api = new ChampionsController(new StubData());
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon"));
Assert.IsNotNull(a);
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon");
//Assert.AreEqual<ChampionDTO>(champ,((CreatedAtActionResult)a).Value);
}
}
}

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class ChampionClassDTO
{
public string Name;
public ChampionClassDTO(string name) {
this.Name = name;
}
}
}

@ -5,26 +5,19 @@ namespace DTO
{
public class ChampionDTO
{
public ChampionDTO(string name, string bio, string icon)
public ChampionDTO(string name, string bio, string icon, string championClassDTO)
{
Name = name;
Bio = bio;
Icon = icon;
Class = championClassDTO;
}
//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; }
public string Class { get; set; }
public bool equals(ChampionDTO other)
{
return other.Name==this.Name && other.Bio==this.Bio && other.Icon==this.Icon;

@ -0,0 +1,23 @@
using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO
{
public class SkinDTO
{
public string Name { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public SkinDTO(string name,string description,string icon) {
this.Name = name;
this.Description = description;
this.Icon = icon;
}
}
}
Loading…
Cancel
Save