|
|
@ -12,32 +12,32 @@ namespace apiLOL.Controllers
|
|
|
|
|
|
|
|
|
|
|
|
public class ControllerChampions : Controller
|
|
|
|
public class ControllerChampions : Controller
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private readonly IDataManager data;
|
|
|
|
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;
|
|
|
|
private readonly ILogger _logger;
|
|
|
|
|
|
|
|
|
|
|
|
public ControllerChampions(IDataManager manager, ILogger<ControllerChampions> log)
|
|
|
|
public ControllerChampions(IDataManager manager, ILogger<ControllerChampions> log)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
data = manager;
|
|
|
|
_data = manager;
|
|
|
|
_logger = log;
|
|
|
|
_logger = log;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET: api/<ControllerLol>
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
[HttpGet]
|
|
|
|
public async Task<IActionResult> Get([FromQuery]int index = 0, int count = 10, string? name = "")
|
|
|
|
[ProducesResponseType(typeof(ChampionPageDTO), 200)]
|
|
|
|
|
|
|
|
public async Task<IActionResult> Get([FromQuery] int index = 0, int count = 10, string? name = "")
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
_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();
|
|
|
|
int nbChampions = await _data.ChampionsMgr.GetNbItems();
|
|
|
|
_logger.LogInformation($"Nombre de champions : {nbChampions}");
|
|
|
|
_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 champions = await _data.ChampionsMgr.GetItems(index, nbChampions);
|
|
|
|
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 filteredChampions = champions.Where(Model => Model.Name.Contains(name)).Skip(index * count).Take(count);
|
|
|
|
|
|
|
|
var championDTO = filteredChampions.Select(Model => Model.ToDTO());
|
|
|
|
|
|
|
|
|
|
|
|
var page = new ChampionPageDTO
|
|
|
|
var page = new ChampionPageDTO
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Data = (IEnumerable<ChampionDTO>)champs,
|
|
|
|
Data = championDTO,
|
|
|
|
Index = index,
|
|
|
|
Index = index,
|
|
|
|
Count = count,
|
|
|
|
Count = count,
|
|
|
|
TotalCount = nbChampions
|
|
|
|
TotalCount = nbChampions
|
|
|
@ -46,18 +46,18 @@ namespace apiLOL.Controllers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET api/<ControllerLol>/Charle
|
|
|
|
|
|
|
|
[HttpGet]
|
|
|
|
[HttpGet]
|
|
|
|
[Route("{name}")]
|
|
|
|
[Route("{name}")]
|
|
|
|
|
|
|
|
[ProducesResponseType(typeof(ChampionDTO), 200)]
|
|
|
|
public async Task<IActionResult> GetChampion(string name)
|
|
|
|
public async Task<IActionResult> GetChampion(string name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}");
|
|
|
|
_logger.LogInformation($"methode GetChampion de ControllerChampions appelée avec le paramètre {name}");
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1));
|
|
|
|
var champs = (await _data.ChampionsMgr.GetItemsByName(name, 0, 1));
|
|
|
|
return Ok(champs.First().ToDTO());
|
|
|
|
return Ok(champs.First().ToDTO());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch(Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_logger.LogError($"erreur methode Get de ControllerChampions: {ex}");
|
|
|
|
_logger.LogError($"erreur methode Get de ControllerChampions: {ex}");
|
|
|
|
return BadRequest("erreur de nom de champion");
|
|
|
|
return BadRequest("erreur de nom de champion");
|
|
|
@ -65,7 +65,6 @@ namespace apiLOL.Controllers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// POST api/<ControllerLol>
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
[HttpPost]
|
|
|
|
public async Task<IActionResult> Post(ChampionDTO champDTO)
|
|
|
|
public async Task<IActionResult> Post(ChampionDTO champDTO)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -73,9 +72,9 @@ namespace apiLOL.Controllers
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Champion tmp = champDTO.ToModel();
|
|
|
|
Champion tmp = champDTO.ToModel();
|
|
|
|
Champion champion = await data.ChampionsMgr.AddItem(tmp);
|
|
|
|
Champion champion = await _data.ChampionsMgr.AddItem(tmp);
|
|
|
|
ChampionDTO dtoChamp = champion.ToDTO();
|
|
|
|
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)
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -84,15 +83,15 @@ namespace apiLOL.Controllers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// PUT api/<ControllerLol>/5
|
|
|
|
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
public async Task<IActionResult> Put(string name, string bio)
|
|
|
|
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
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var champs = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First();
|
|
|
|
var champs = (await _data.ChampionsMgr.GetItemsByName(name, 0, 1)).First();
|
|
|
|
champs.Bio = bio;
|
|
|
|
champs.Bio = bio;
|
|
|
|
return Ok(champs.ToDTO());
|
|
|
|
return Ok(champs.ToDTO());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -103,7 +102,6 @@ namespace apiLOL.Controllers
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DELETE api/<ControllerLol>/5
|
|
|
|
|
|
|
|
[HttpDelete("{name}")]
|
|
|
|
[HttpDelete("{name}")]
|
|
|
|
public async Task<IActionResult> Delete(string name)
|
|
|
|
public async Task<IActionResult> Delete(string name)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -111,8 +109,8 @@ namespace apiLOL.Controllers
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
try
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First();
|
|
|
|
var champ = (await _data.ChampionsMgr.GetItemsByName(name, 0, 1)).First();
|
|
|
|
await data.ChampionsMgr.DeleteItem(champ);
|
|
|
|
await _data.ChampionsMgr.DeleteItem(champ);
|
|
|
|
return Ok(champ.ToDTO());
|
|
|
|
return Ok(champ.ToDTO());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
catch (Exception ex)
|
|
|
@ -123,4 +121,41 @@ 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpGet()]
|
|
|
|
|
|
|
|
public string Get(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return "Version 2 of GET";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
|
|
|
public void Post([FromBody] string value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
|
|
|
public void Put(int id, [FromBody] string value)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
|
|
|
public void Delete(int id)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|