|
|
|
@ -23,12 +23,14 @@ namespace ApiLol.Controllers
|
|
|
|
|
// GET: api/<ValuesController>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> Get([FromQuery] PageRequest pageRequest)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
int nbTotal = await _manager.ChampionsMgr.GetNbItems();
|
|
|
|
|
if (pageRequest.count + pageRequest.index > nbTotal)
|
|
|
|
|
{
|
|
|
|
|
_logger.LogWarning($"too many, maximum {nbTotal}");
|
|
|
|
|
return BadRequest("Champion limit exceed");
|
|
|
|
|
return BadRequest($"Champion limit exceed, max {nbTotal}");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_logger.LogInformation($"method Get call");
|
|
|
|
@ -36,10 +38,18 @@ namespace ApiLol.Controllers
|
|
|
|
|
.Select(x => x.ToDto());
|
|
|
|
|
return Ok(dtos);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET api/<ValuesController>/5
|
|
|
|
|
[HttpGet("{name}")]
|
|
|
|
|
public async Task<IActionResult> Get(string name)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"method GetByName call with {name}");
|
|
|
|
|
var dtos = (await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems()))
|
|
|
|
@ -51,10 +61,18 @@ namespace ApiLol.Controllers
|
|
|
|
|
}
|
|
|
|
|
return Ok(dtos);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST api/<ValuesController>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Post([FromBody] ChampionDto champion)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"method Post call");
|
|
|
|
|
var dtos = (await _manager.ChampionsMgr.GetItemsByName(champion.Name, 0, await _manager.ChampionsMgr.GetNbItems()));
|
|
|
|
@ -65,10 +83,18 @@ namespace ApiLol.Controllers
|
|
|
|
|
return CreatedAtAction(nameof(Get),
|
|
|
|
|
(await _manager.ChampionsMgr.AddItem(champion.ToModel())).ToDto());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PUT api/<ValuesController>/5
|
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
|
public async Task<IActionResult> Put(string name, [FromBody] ChampionDto champion)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"method Put call with {name}");
|
|
|
|
|
var dtos = (await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
|
|
|
|
@ -87,10 +113,53 @@ namespace ApiLol.Controllers
|
|
|
|
|
}
|
|
|
|
|
return Ok(await _manager.ChampionsMgr.UpdateItem(dtos.First(), champion.ToModel()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("/{name}/skins")]
|
|
|
|
|
public async Task<ActionResult<Skin>> GetChampionsSkins(string name)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var champions = await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems());
|
|
|
|
|
//skinsDTO
|
|
|
|
|
IEnumerable<SkinDto> res = champions.First().Skins.Select(e => e.ToDto());
|
|
|
|
|
|
|
|
|
|
return Ok(res);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpGet("/{name}/skills")]
|
|
|
|
|
public async Task<ActionResult<Skin>> GetChampionsSkills(string name)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var champions = await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems());
|
|
|
|
|
//SkillDTO
|
|
|
|
|
IEnumerable<SkillDto> res = champions.First().Skills.Select(e => e.ToDto());
|
|
|
|
|
|
|
|
|
|
return Ok(res);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DELETE api/<ValuesController>/5
|
|
|
|
|
[HttpDelete("{name}")]
|
|
|
|
|
public async Task<IActionResult> Delete(string name)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
_logger.LogInformation($"method Delete call with {name}");
|
|
|
|
|
var dtos = (await _manager.ChampionsMgr.GetItemsByName(name, 0, await _manager.ChampionsMgr.GetNbItems()));
|
|
|
|
@ -101,5 +170,10 @@ namespace ApiLol.Controllers
|
|
|
|
|
}
|
|
|
|
|
return Ok(await _manager.ChampionsMgr.DeleteItem(dtos.First()));
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|