You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
69 lines
1.7 KiB
using Microsoft.AspNetCore.Mvc;
|
|
using Model;
|
|
using StubLib;
|
|
using System.Xml.Linq;
|
|
using static StubLib.StubData;
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
namespace apiLOL.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("api/[controller]")]
|
|
public class ControllerChampions : Controller
|
|
{
|
|
private readonly IDataManager data;
|
|
|
|
|
|
|
|
public ControllerChampions(IDataManager manager)
|
|
{
|
|
data = manager;
|
|
}
|
|
|
|
|
|
// GET: api/<ControllerLol>
|
|
[HttpGet]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
var champs = (await data.ChampionsMgr.GetItems(0, await data.ChampionsMgr.GetNbItems())).Select(Model => Model.ToDTO());
|
|
return Ok(champs);
|
|
}
|
|
|
|
|
|
// GET api/<ControllerLol>/Charle
|
|
[HttpGet]
|
|
[Route("{name}")]
|
|
public async Task<IActionResult> GetChampion(string name)
|
|
{
|
|
var champs = (await data.ChampionsMgr.GetItemsByName(name,0,1)).First();
|
|
return Ok(champs.ToDTO());
|
|
}
|
|
|
|
|
|
// POST api/<ControllerLol>
|
|
[HttpPost]
|
|
public async Task<IActionResult> Post(ChampionDTO champDTO)
|
|
{
|
|
Champion tmp = champDTO.ToModel();
|
|
Champion champion = await data.ChampionsMgr.AddItem(tmp);
|
|
ChampionDTO dtoChamp = champion.ToDTO();
|
|
return CreatedAtAction(nameof(GetChampion), new { name = dtoChamp.Name }, dtoChamp);
|
|
}
|
|
|
|
// PUT api/<ControllerLol>/5
|
|
[HttpPut("{id}")]
|
|
public void Put(int id, [FromBody] string value)
|
|
{
|
|
}
|
|
|
|
// DELETE api/<ControllerLol>/5
|
|
[HttpDelete("{name}")]
|
|
public async void Delete(String name)
|
|
{
|
|
var champ = (await data.ChampionsMgr.GetItemsByName(name, 0, 1)).First();
|
|
data.ChampionsMgr.DeleteItem(champ);
|
|
}
|
|
|
|
}
|
|
}
|