|
|
|
@ -30,9 +30,18 @@ namespace API_LoL_Project.Controllers
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<IEnumerable<ChampionDTO>>> Get()
|
|
|
|
|
{
|
|
|
|
|
var champions = await dataManager.GetItems(0, await dataManager.GetNbItems());
|
|
|
|
|
IEnumerable<ChampionDTO> res = champions.Select(c => c.toDTO());
|
|
|
|
|
return Ok(res);
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var champions = await dataManager.GetItems(0, await dataManager.GetNbItems());
|
|
|
|
|
IEnumerable<ChampionDTO> res = champions.Select(c => c.toDTO());
|
|
|
|
|
return Ok(res);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -43,10 +52,19 @@ namespace API_LoL_Project.Controllers
|
|
|
|
|
public async Task<ActionResult<ChampionDTO>> Get(string name)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
var champion = await dataManager
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var champion = await dataManager
|
|
|
|
|
.GetItemsByName(name, 0, await dataManager.GetNbItems());
|
|
|
|
|
ChampionDTO res = champion.First().toDTO();
|
|
|
|
|
return Ok(res);
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
return Ok(new { result = champion.First().toDTO() });
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -54,32 +72,59 @@ namespace API_LoL_Project.Controllers
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Post([FromBody] ChampionDTO value)
|
|
|
|
|
{
|
|
|
|
|
await dataManager.AddItem(value.toModel());
|
|
|
|
|
return Ok();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var newChampion = value.toModel();
|
|
|
|
|
await dataManager.AddItem(newChampion);
|
|
|
|
|
return CreatedAtAction(nameof(Get), newChampion) ;
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PUT api/<ChampionController>/5
|
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
|
public async Task<IActionResult> Put(string name, [FromBody] ChampionDTO value)
|
|
|
|
|
{
|
|
|
|
|
var champion = await dataManager
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var champion = await dataManager
|
|
|
|
|
.GetItemsByName(name, 0, await dataManager.GetNbItems());
|
|
|
|
|
await dataManager.UpdateItem(champion.First(), value.toModel());
|
|
|
|
|
return Ok();
|
|
|
|
|
await dataManager.UpdateItem(champion.First(), value.toModel());
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
catch(Exception e)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DELETE api/<ChampionController>/5
|
|
|
|
|
[HttpDelete("{name}")]
|
|
|
|
|
public async Task<IActionResult> Delete(string name)
|
|
|
|
|
{
|
|
|
|
|
var champion = await dataManager
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var champion = await dataManager
|
|
|
|
|
.GetItemsByName(name, 0, await dataManager.GetNbItems());
|
|
|
|
|
if (champion != null) await dataManager.DeleteItem(champion.First());
|
|
|
|
|
else
|
|
|
|
|
if (champion != null) await dataManager.DeleteItem(champion.First());
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
return NotFound();
|
|
|
|
|
return BadRequest(e.Message);
|
|
|
|
|
}
|
|
|
|
|
return Ok();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* [HttpGet]
|
|
|
|
|