|
|
|
@ -0,0 +1,73 @@
|
|
|
|
|
using APILOL.Mapper;
|
|
|
|
|
using DTO;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Model;
|
|
|
|
|
using StubLib;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
|
|
|
|
|
|
namespace APILOL.Controllers
|
|
|
|
|
{
|
|
|
|
|
[Route("api/[controller]")]
|
|
|
|
|
[ApiController]
|
|
|
|
|
public class ChampionsController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
IChampionsManager managerChampions;
|
|
|
|
|
|
|
|
|
|
public ChampionsController(IDataManager manager)
|
|
|
|
|
{
|
|
|
|
|
managerChampions = manager.ChampionsMgr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET: api/<ChampionController>
|
|
|
|
|
[HttpGet]
|
|
|
|
|
|
|
|
|
|
public async Task<IActionResult> Get()
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<ChampionDTO> championDTOs = (await managerChampions.GetItems(0, await managerChampions.GetNbItems())).Select(x => x.ToDTO());
|
|
|
|
|
|
|
|
|
|
if (championDTOs != null)
|
|
|
|
|
{
|
|
|
|
|
return Ok(championDTOs);
|
|
|
|
|
}
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET api/<ChampionController>/5
|
|
|
|
|
[HttpGet("{name}")]
|
|
|
|
|
public async Task<IActionResult> GetAsync(String name)
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<Champion> champ = await managerChampions.GetItemsByName(name, 0, await managerChampions.GetNbItems());
|
|
|
|
|
if (champ.Count() != 0)
|
|
|
|
|
{
|
|
|
|
|
return Ok(champ.First().ToDTO());
|
|
|
|
|
}
|
|
|
|
|
return NotFound();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// POST api/<ChampionController>
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> Post([FromBody] ChampionDTO champion)
|
|
|
|
|
{
|
|
|
|
|
return CreatedAtAction(nameof(Get), await managerChampions.AddItem(champion.ToModel()));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PUT api/<ChampionController>/5
|
|
|
|
|
[HttpPut("{name}")]
|
|
|
|
|
public async void Put(String name, [FromBody] ChampionDTO champion)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DELETE api/<ChampionController>/5
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public async void Delete(int id)
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|