|
|
@ -12,13 +12,20 @@ namespace APILOL.Controllers
|
|
|
|
[ApiController]
|
|
|
|
[ApiController]
|
|
|
|
public class ChampionsController : ControllerBase
|
|
|
|
public class ChampionsController : ControllerBase
|
|
|
|
{
|
|
|
|
{
|
|
|
|
IChampionsManager dataManager = new StubData().ChampionsMgr;
|
|
|
|
IChampionsManager dataManager;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ChampionsController(IDataManager dataManager)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
this.dataManager = dataManager.ChampionsMgr;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET: api/<ChampionController>
|
|
|
|
// GET: api/<ChampionController>
|
|
|
|
[HttpGet]
|
|
|
|
[HttpGet]
|
|
|
|
public async Task<IActionResult> Get()
|
|
|
|
public async Task<IActionResult> Get(int index, int count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var champions = await dataManager.GetItems(0, await dataManager.GetNbItems());
|
|
|
|
var champions = await dataManager.GetItems(index, count);
|
|
|
|
IEnumerable<ChampionDTO> items = champions.Select(c => c.ToDto());
|
|
|
|
IEnumerable<ChampionDTO> items = champions.Select(c => c.ToDto());
|
|
|
|
return Ok(items);
|
|
|
|
return Ok(items);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -44,14 +51,21 @@ namespace APILOL.Controllers
|
|
|
|
|
|
|
|
|
|
|
|
// PUT api/<ChampionController>/5
|
|
|
|
// PUT api/<ChampionController>/5
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
public void Put(string name, [FromBody] ChampionDTO championDTO)
|
|
|
|
public async Task<IActionResult> PutAsync(string name, [FromBody] ChampionDTO championDTO)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var dtos = (await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Ok(dataManager.UpdateItem(dtos.First(), championDTO.ToModel()));
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// DELETE api/<ChampionController>/5
|
|
|
|
// DELETE api/<ChampionController>/5
|
|
|
|
[HttpDelete("{name}")]
|
|
|
|
[HttpDelete("{name}")]
|
|
|
|
public void Delete(string name)
|
|
|
|
public async Task<IActionResult> Delete(string name)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
var dtos = (await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
|
|
|
|
|
|
|
|
return Ok(dataManager.DeleteItem(dtos.First()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|