|
|
|
@ -0,0 +1,67 @@
|
|
|
|
|
using API_LoL_Project.Mapper;
|
|
|
|
|
using DTO;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Model;
|
|
|
|
|
using StubLib;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
|
|
|
|
|
|
namespace API_LoL_Project.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ChampionsController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
IChampionsManager dataManager = new StubData().ChampionsMgr;
|
|
|
|
|
|
|
|
|
|
// GET: api/<ChampionController>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<IActionResult> Get()
|
|
|
|
|
{
|
|
|
|
|
var champions = await dataManager.GetItems(0, await dataManager.GetNbItems());
|
|
|
|
|
|
|
|
|
|
return Ok(new { result = champions.Select(c => c.toDTO())});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET api/<ChampionController>/5
|
|
|
|
|
[HttpGet("{name}")]
|
|
|
|
|
public async Task<IActionResult> Get(string name)
|
|
|
|
|
{
|
|
|
|
|
var champion = await dataManager
|
|
|
|
|
.GetItemsByName(name, 0, await dataManager.GetNbItems());
|
|
|
|
|
|
|
|
|
|
return Ok(new { result = champion.First().toDTO() });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST api/<ChampionController>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Post([FromBody] ChampionDTO value)
|
|
|
|
|
{
|
|
|
|
|
await dataManager.AddItem(value.toModel());
|
|
|
|
|
return Ok();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PUT api/<ChampionController>/5
|
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
|
public async Task<IActionResult> Put(string name, [FromBody] ChampionDTO value)
|
|
|
|
|
{
|
|
|
|
|
var champion = await dataManager
|
|
|
|
|
.GetItemsByName(name, 0, await dataManager.GetNbItems());
|
|
|
|
|
await dataManager.UpdateItem(champion.First(), value.toModel());
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DELETE api/<ChampionController>/5
|
|
|
|
|
[HttpDelete("{name}")]
|
|
|
|
|
public async Task<IActionResult> Delete(string name)
|
|
|
|
|
{
|
|
|
|
|
var champion = await dataManager
|
|
|
|
|
.GetItemsByName(name, 0, await dataManager.GetNbItems());
|
|
|
|
|
await dataManager.DeleteItem(champion.First());
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|