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.
62 lines
1.7 KiB
62 lines
1.7 KiB
using APILOL.Mapper;
|
|
using DTO;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Model;
|
|
using StubLib;
|
|
|
|
// 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 dataManager = new StubData().ChampionsMgr;
|
|
|
|
// GET: api/<ChampionController>
|
|
[HttpGet]
|
|
public async Task<IActionResult> Get()
|
|
{
|
|
var champions = await dataManager.GetItems(0, await dataManager.GetNbItems());
|
|
IEnumerable<ChampionDTO> items = champions.Select(c => c.ToDto());
|
|
return Ok(items);
|
|
}
|
|
|
|
// GET api/<ChampionController>/5
|
|
[HttpGet("{name}")]
|
|
public async Task<IActionResult> Get(string name)
|
|
{
|
|
if (dataManager.GetNbItemsByName(name) != null)
|
|
{
|
|
return Ok(dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()));
|
|
}
|
|
return NotFound();
|
|
}
|
|
|
|
// POST api/<ChampionController>
|
|
[HttpPost]
|
|
public async Task<IActionResult> Post([FromBody] ChampionDTO championDTO)
|
|
{
|
|
|
|
return CreatedAtAction(nameof(Get),(await dataManager.AddItem(championDTO.ToModel())).ToDto);
|
|
}
|
|
|
|
// PUT api/<ChampionController>/5
|
|
[HttpPut("{name}")]
|
|
public void Put(string name, [FromBody] ChampionDTO championDTO)
|
|
{
|
|
}
|
|
|
|
// DELETE api/<ChampionController>/5
|
|
[HttpDelete("{name}")]
|
|
public void Delete(string name)
|
|
{
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
var champion = new Champion("");
|
|
var dto = ChampionMapper.ToDto(champion);
|
|
*/ |