|
|
|
@ -6,13 +6,14 @@ using Model;
|
|
|
|
|
|
|
|
|
|
namespace apiLOL.Controllers
|
|
|
|
|
{
|
|
|
|
|
[ApiController]
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/v1/[controller]")]
|
|
|
|
|
[ApiVersion("1.0")]
|
|
|
|
|
|
|
|
|
|
public class ControllerChampions : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly IDataManager data;
|
|
|
|
|
|
|
|
|
|
// EFdata manager qui implémente l'interface IDataManager
|
|
|
|
|
// coté client : Refaire un APIdata manager qui implémente l'interface IDataManager
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
@ -26,20 +27,23 @@ namespace apiLOL.Controllers
|
|
|
|
|
|
|
|
|
|
// GET: api/<ControllerLol>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> Get([FromQuery]int index = 0, int count = 10, string? name = "")
|
|
|
|
|
public async Task<IActionResult> Get([FromQuery] int index = 0, int count = 10, string? name = "")
|
|
|
|
|
{
|
|
|
|
|
//FromQuery permet de filtrer dans la collection de champions en fonction du nom
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"methode Get de ControllerChampions appelée index:{index}, count: {count} et name:{name}");
|
|
|
|
|
_logger.LogInformation(
|
|
|
|
|
$"methode Get de ControllerChampions appelée index:{index}, count: {count} et name:{name}");
|
|
|
|
|
int nbChampions = await data.ChampionsMgr.GetNbItems();
|
|
|
|
|
_logger.LogInformation($"Nombre de champions : {nbChampions}");
|
|
|
|
|
|
|
|
|
|
//var champs = (await data.ChampionsMgr.GetItems(index, count)).Where(Model => Model.Name.Contains(name)).Select(Model => Model.ToDTO());
|
|
|
|
|
var champs = (await data.ChampionsMgr.GetItems(index, await data.ChampionsMgr.GetNbItems())).Where(Model => Model.Name.Contains(name)).Skip(index * count).Take(count).Select(Model => Model.ToDTO());
|
|
|
|
|
var champs = (await data.ChampionsMgr.GetItems(index, await data.ChampionsMgr.GetNbItems()))
|
|
|
|
|
.Where(Model => Model.Name.Contains(name)).Skip(index * count).Take(count)
|
|
|
|
|
.Select(Model => Model.ToDTO());
|
|
|
|
|
|
|
|
|
|
var page = new ChampionPageDTO
|
|
|
|
|
{
|
|
|
|
|
Data = (IEnumerable<ChampionDTO>)champs,
|
|
|
|
|
Data = (IEnumerable<ChampionDTO>) champs,
|
|
|
|
|
Index = index,
|
|
|
|
|
Count = count,
|
|
|
|
|
TotalCount = nbChampions
|
|
|
|
@ -59,11 +63,11 @@ namespace apiLOL.Controllers
|
|
|
|
|
var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1));
|
|
|
|
|
return Ok(champs.First().ToDTO());
|
|
|
|
|
}
|
|
|
|
|
catch(Exception ex)
|
|
|
|
|
{
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogError($"erreur methode Get de ControllerChampions: {ex}");
|
|
|
|
|
return BadRequest("erreur de nom de champion");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -77,7 +81,7 @@ namespace apiLOL.Controllers
|
|
|
|
|
Champion tmp = champDTO.ToModel();
|
|
|
|
|
Champion champion = await data.ChampionsMgr.AddItem(tmp);
|
|
|
|
|
ChampionDTO dtoChamp = champion.ToDTO();
|
|
|
|
|
return CreatedAtAction(nameof(GetChampion), new { name = dtoChamp.Name }, dtoChamp);
|
|
|
|
|
return CreatedAtAction(nameof(GetChampion), new {name = dtoChamp.Name}, dtoChamp);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
@ -90,7 +94,8 @@ namespace apiLOL.Controllers
|
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
|
public async Task<IActionResult> Put(string name, string bio)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"methode Put de ControllerChampions appelée avec le paramètre name: {name} et bio: {bio}");
|
|
|
|
|
_logger.LogInformation(
|
|
|
|
|
$"methode Put de ControllerChampions appelée avec le paramètre name: {name} et bio: {bio}");
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
@ -125,4 +130,45 @@ namespace apiLOL.Controllers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ApiController]
|
|
|
|
|
[Route("api/v2/[controller]")]
|
|
|
|
|
[ApiVersion("2.0")]
|
|
|
|
|
|
|
|
|
|
public class ControllerChampionsSecondVersion : Controller
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
public ControllerChampionsSecondVersion(ILogger<ControllerChampions> log)
|
|
|
|
|
{
|
|
|
|
|
_logger = log;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET api/<ControllerSkins>/5
|
|
|
|
|
[HttpGet()]
|
|
|
|
|
public string Get(int id)
|
|
|
|
|
{
|
|
|
|
|
return "Version 2 of GET";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST api/<ControllerSkins>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Post([FromBody] string value)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PUT api/<ControllerSkins>/5
|
|
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
public void Put(int id, [FromBody] string value)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DELETE api/<ControllerSkins>/5
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public void Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|