avacencement filtarage panigation
continuous-integration/drone/push Build is failing Details

master
Jolys Enzo 2 years ago
parent 5f5777623d
commit 61c5cbff4e

@ -1,9 +1,11 @@
using Api_lol.Factories;
using DTO;
using DTO.DtoControlleur.Champions;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
using System;
using System.Xml.Linq;
namespace Api_lol.Controllers
@ -24,12 +26,32 @@ namespace Api_lol.Controllers
[HttpGet]
public async Task<IActionResult> Get()
public async Task<IActionResult> Get(int index = 0,int count = 0,string classe = "All")
{
var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ModelToDto());
//comm
IEnumerable<DtoChampions> champs = new List<DtoChampions>();
return Ok(champs);
try
{
if (count == 0)
{
count = await data.ChampionsMgr.GetNbItems();
}
if (classe != "All")
{
champs = (await data.ChampionsMgr.GetItems(index, count)).Where(e => e.Class.ToString() == classe).Select(Model => Model.ModelToDto());
}
else
{
champs = (await data.ChampionsMgr.GetItems(index, count)).Select(Model => Model.ModelToDto());
}
}
catch(Exception ex)
{
return BadRequest(ex.Message);
}
GetChampions dto = new GetChampions(champs.ToList(), index, count);
return Ok(dto);
}
@ -37,7 +59,16 @@ namespace Api_lol.Controllers
public async Task<IActionResult> Post(DtoChampions champDTO)
{
Champion tmp = champDTO.DtoToModel();
Champion champion = await data.ChampionsMgr.AddItem(tmp);
Champion champion;
try
{
champion = await data.ChampionsMgr.AddItem(tmp);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
DtoChampions dtoChamp = champion.ModelToDto();
return CreatedAtAction(nameof(GetChampion),new { name = dtoChamp.name},dtoChamp);
}
@ -48,7 +79,16 @@ namespace Api_lol.Controllers
[Route("{name}")]
public async Task<IActionResult> GetChampion(string name)
{
Champion champion = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).First(i => i.Name == name);
Champion champion;
try
{
champion = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).First(i => i.Name == name);
}
catch (Exception ex)
{
return BadRequest(ex.Message);
}
if ( champion == null)
{
return BadRequest();
@ -57,5 +97,22 @@ namespace Api_lol.Controllers
return Ok(result);
}
[HttpDelete]
public async Task<IActionResult> DeleteChampion(string name = "")
{
Champion champion;
try
{
champion = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).First(e => e.Name == name);
} catch (Exception ex)
{
return BadRequest(ex.Message);
}
await data.ChampionsMgr.DeleteItem(champion);
return Ok(champion.ModelToDto());
}
}
}

@ -1,5 +1,6 @@
using Api_lol.Factories;
using DTO;
using DTO.DtoControlleur.Skins;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Model;
@ -22,11 +23,31 @@ namespace Api_lol.Controllers
}
[HttpGet]
public async Task<IActionResult> Get()
public async Task<IActionResult> Get(int index = 0,int count = 0,float price = 0)
{
var skins = (await data.SkinsMgr.GetItems(0, await data.SkinsMgr.GetNbItems())).Select(Model => Model.ModelToDto());
IEnumerable<DtoSkins> skins = new List<DtoSkins>();
try
{
if (count == 0)
{
count = await data.SkinsMgr.GetNbItems();
}
if ( price != 0 )
{
skins = (await data.SkinsMgr.GetItems(index, count)).Where(e => e.Price == price).Select(Model => Model.ModelToDto());
}
else
{
skins = (await data.SkinsMgr.GetItems(index, count)).Select(Model => Model.ModelToDto());
}
}
catch(Exception ex)
{
return BadRequest(ex.Message);
}
GetSkins dto = new GetSkins(skins.ToList(),index,count);
return Ok(skins);
return Ok(dto);
}
[HttpGet]

@ -13,7 +13,14 @@ namespace Api_lol.Factories
public static DtoChampions ModelToDto(this Champion champ)
{
return new DtoChampions(champ.Name);
DtoChampions dto = new DtoChampions();
dto.name = champ.Name;
dto.classe = champ.Class.ToString();
dto.bio = champ.Bio;
dto.icon = champ.Icon;
return dto;
}
}
}

@ -7,7 +7,14 @@ namespace Api_lol.Factories
{
public static DtoSkins ModelToDto(this Skin skin)
{
return new DtoSkins(skin.Name);
DtoSkins dto = new DtoSkins();
dto.name = skin.Name;
dto.description = skin.Description;
dto.price = skin.Price;
dto.icon = skin.Icon;
return dto;
}
public static Skin DtoToModel(this DtoSkins skinDto,Champion champ)

@ -10,9 +10,9 @@ namespace DTO
{
public string name { get; set; }
public DtoChampions(string name)
{
this.name = name;
}
public string classe { get; set; }
public string bio { get; set; }
public string icon { get; set; }
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO.DtoControlleur.Champions
{
public class GetChampions
{
public List<DtoChampions> listeChampions { get; set; }
public int index { get; set; }
public int count { get; set; }
public GetChampions(List<DtoChampions> liste, int indexDto,int countDto)
{
index = indexDto;
count = countDto;
listeChampions = liste;
}
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTO.DtoControlleur.Skins
{
public class GetSkins
{
public List<DtoSkins> listeSkins { get; set; }
public int index { get; set; }
public int count { get; set; }
public GetSkins(List<DtoSkins> liste, int indexDto, int countDto)
{
index = indexDto;
count = countDto;
listeSkins = liste;
}
}
}

@ -10,9 +10,12 @@ namespace DTO
{
public string name { get; set; }
public DtoSkins(string name)
{
this.name = name;
}
public float price { get; set; }
public string description { get; set; }
public string icon { get; set; }
}
}
Loading…
Cancel
Save