Merge pull request 'advancedController' (#28) from advancedController into master
continuous-integration/drone/push Build is failing Details

Reviewed-on: #28
pull/29/head
Corentin RICHARD 2 years ago
commit 5554d01761

@ -30,6 +30,12 @@ namespace API_LoL.Controllers
// GET api/<ChampionController>/5
[HttpGet("count")]
public async Task<IActionResult> GetCount()
{
return Ok(ChampionsManager.GetNbItems());
}
[HttpGet]
public async Task<IActionResult> Get(string? name = null,String? skill = null, String? characteristic = null,int index = 0,int size =10)
{
@ -103,8 +109,27 @@ namespace API_LoL.Controllers
else { return NoContent(); }
}
// POST api/<ChampionController>
[HttpPost]
//[HttpGet("name/skills")]
//public async Task<IActionResult> GetSkillsByName(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)
@ -113,21 +138,43 @@ namespace API_LoL.Controllers
}
else
{
var champ = await ChampionsManager.GetItemsByName(champion.Name, 0, 1);
if(champ.FirstOrDefault().Name == champion.Name)
{
return Conflict(champion);
}
await ChampionsManager.AddItem(champion.ToChampion());
return CreatedAtAction("Post",champion);
}
}
// PUT api/<ChampionController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
[HttpPut("name")]
public async Task<IActionResult> Put(string name, ChampionDTO championDTO)
{
if(string.IsNullOrEmpty(name))
return BadRequest();
if(championDTO == null)
return UnprocessableEntity();
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if (list.Count() == 1)
{
return Ok(ChampionsManager.UpdateItem(list.First(), championDTO.ToChampion()));
}
else { return NoContent(); }
}
// DELETE api/<ChampionController>/5
[HttpDelete("{id}")]
public void Delete(int id)
[HttpDelete("name")]
public async Task<IActionResult> Delete(string name)
{
if (string.IsNullOrEmpty(name))
return BadRequest();
var list = await ChampionsManager.GetItemsByName(name, 0, 1);
if(list.Count() == 1){
return Ok(await ChampionsManager.DeleteItem(list.First()));
}else { return NoContent(); }
}
}
}

@ -12,19 +12,13 @@ namespace DTO.Mapper
{
public static ChampionDTO ToDTO(this Champion champion)
{
return new ChampionDTO(champion.Name, champion.Bio, champion.Icon,champion.Class.ToDTO().ToString());
//return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Skills);
return new ChampionDTO(champion.Name, champion.Bio, champion.Icon, champion.Class.ToDTO(), champion.Image.Base64);
}
public static Champion ToChampion(this ChampionDTO champion)
{
Champion champ = new Champion(champion.Name, champion.Class.ToChampionClass(), champion.Icon, "", champion.Bio);
return new Champion(champion.Name, champClass: champion.Class.ToChampionClass(),icon: champion.Icon,bio: champion.Bio,image :champion.Image);
//foreach (Skill skill in champion.Skills)
//{
// champ.AddSkill(skill);
//}
return champ;
}
}
}

@ -7,12 +7,12 @@ namespace API_LoL.Mapper
{
public static SkinDTO ToDTO(this Skin skin)
{
return new SkinDTO(skin.Name, skin.Description, skin.Icon);
return new SkinDTO(skin.Name, skin.Description, skin.Icon,skin.Image.Base64,skin.Price);
}
public static Skin ToSkin(this SkinDTO skin)
{
return new Skin(skin.Name, null, icon:skin.Icon) ;
return new Skin(skin.Name, null,price: skin.Price, icon:skin.Icon,image: skin.Image,description: skin.Description) ;
}
}
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

@ -21,7 +21,7 @@ namespace Api_UT
public async Task Get_Default_OkList()
{
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") };
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", "", "", "Assassin"), new ChampionDTO("Aatrox", "", "", "Fighter") };
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", "", "", "Assassin"), new ChampionDTO("Akshan", "", "", "Marksman") };
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", "Assassin"));
IActionResult a = await api.Post(new ChampionDTO("nom","bio","icon", "Assassin",""));
Assert.IsNotNull(a);
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin");
ChampionDTO champ = new ChampionDTO("nom", "bio", "icon","Assassin", "");
Assert.IsTrue(champ.equals((ChampionDTO)((CreatedAtActionResult)a).Value));
}

@ -5,17 +5,19 @@ namespace DTO
{
public class ChampionDTO
{
public ChampionDTO(string name, string bio, string icon, string championClassDTO)
public ChampionDTO(string name, string bio, string icon, string Class, string image)
{
Name = name;
Bio = bio;
Icon = icon;
Class = championClassDTO;
this.Class = Class;
Image = image;
}
public string Name { get; set; }
public string Bio { get; set; }
public string Icon { get; set; }
public string Image { get; set; }
public string Class { get; set; }
public bool equals(ChampionDTO other)

@ -13,10 +13,16 @@ namespace DTO
public string Description { get; set; }
public string Icon { get; set; }
public SkinDTO(string name,string description,string icon) {
public string Image { get; set; }
public float Price { get; set; }
public SkinDTO(string name,string description,string icon,string image,float price) {
this.Name = name;
this.Description = description;
this.Icon = icon;
this.Image = image;
this.Price = price;
}
}

@ -26,7 +26,9 @@ namespace EntityFramework.Manager
{
if (item != null)
{
context.Add(item.ToEntity());
context.SaveChanges();
return item;
}
else
@ -36,9 +38,21 @@ namespace EntityFramework.Manager
}
}
public Task<bool> DeleteItem(Champion? item)
public async Task<bool> DeleteItem(Champion? item)
{
throw new NotImplementedException();
using (var context = new LoLDBContextWithStub())
{
var champ = context.Champions.Select(c => c == item.ToEntity());
if(champ.Count()<1)
{
return false;
}
context.Champions.Remove(item.ToEntity());
context.SaveChanges();
return true;
}
}
public async Task<IEnumerable<Champion?>> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false)
@ -115,9 +129,12 @@ namespace EntityFramework.Manager
}
}
public Task<int> GetNbItems()
public async Task<int> GetNbItems()
{
throw new NotImplementedException();
using(var context = new LoLDBContextWithStub())
{
return context.Champions.Count();
}
}
public Task<int> GetNbItemsByCharacteristic(string charName)
@ -150,9 +167,19 @@ namespace EntityFramework.Manager
throw new NotImplementedException();
}
public Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
public async Task<Champion?> UpdateItem(Champion? oldItem, Champion? newItem)
{
throw new NotImplementedException();
using(var context = new LoLDBContextWithStub())
{
if (oldItem != null && newItem != null)
{
var champ = context.Champions.Where(c => c == oldItem.ToEntity()).First();
champ = newItem.ToEntity();
context.SaveChanges();
return newItem;
}
else { throw new Exception(); }
}
}
}
}

@ -8,7 +8,7 @@ namespace StubLib
private List<Champion> champions = new()
{
new Champion("Akali", ChampionClass.Assassin),
new Champion("Aatrox", ChampionClass.Fighter),
new Champion("Aatrox", ChampionClass.Fighter),
new Champion("Ahri", ChampionClass.Mage),
new Champion("Akshan", ChampionClass.Marksman),
new Champion("Bard", ChampionClass.Support),

Loading…
Cancel
Save