|
|
|
@ -1,9 +1,11 @@
|
|
|
|
|
using System;
|
|
|
|
|
using StubLib;
|
|
|
|
|
using EFLib;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
using Model;
|
|
|
|
|
|
|
|
|
|
// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
|
|
|
|
|
|
|
|
@ -13,43 +15,27 @@ namespace ApiLol.Controllers
|
|
|
|
|
public class ChampionController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<ChampionController> _logger;
|
|
|
|
|
private List<ChampionEntity> champions = new List<ChampionEntity>();
|
|
|
|
|
|
|
|
|
|
private StubData.ChampionsManager championsManager = new StubData.ChampionsManager(new StubData());
|
|
|
|
|
|
|
|
|
|
public ChampionController(ILogger<ChampionController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
champions.Add(new ChampionEntity
|
|
|
|
|
{
|
|
|
|
|
Id = 1,
|
|
|
|
|
Name = "Aurel",
|
|
|
|
|
Bio = "Trop joli",
|
|
|
|
|
Icon = "Moi",
|
|
|
|
|
ChampClass = Model.ChampionClass.Tank
|
|
|
|
|
});
|
|
|
|
|
champions.Add(new ChampionEntity
|
|
|
|
|
{
|
|
|
|
|
Id = 2,
|
|
|
|
|
Name = "Mathilde",
|
|
|
|
|
Bio = "Elle est reloue",
|
|
|
|
|
Icon = "Macheval",
|
|
|
|
|
ChampClass = Model.ChampionClass.Assassin
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// GET: api/champion
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public ActionResult<IEnumerable<ChampionDTO>> Get()
|
|
|
|
|
public async Task<ActionResult<IEnumerable<ChampionDTO>>> Get()
|
|
|
|
|
{
|
|
|
|
|
IEnumerable<ChampionDTO> champs = new List<ChampionDTO>();
|
|
|
|
|
foreach(ChampionEntity arg in champions)
|
|
|
|
|
{
|
|
|
|
|
champs.Append(arg.ToDto());
|
|
|
|
|
}
|
|
|
|
|
return Ok(champs);
|
|
|
|
|
IEnumerable<Champion?> champs = await championsManager.GetItems(0, await championsManager.GetNbItems());
|
|
|
|
|
IEnumerable<ChampionDTO> championDTOs = champs.ToDtos();
|
|
|
|
|
|
|
|
|
|
return Ok(championDTOs);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// GET api/values/5
|
|
|
|
|
/*
|
|
|
|
|
// GET api/champion/5
|
|
|
|
|
[HttpGet("{id}")]
|
|
|
|
|
public ActionResult<ChampionDTO?> Get(int id)
|
|
|
|
|
{
|
|
|
|
@ -60,30 +46,51 @@ namespace ApiLol.Controllers
|
|
|
|
|
}
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// POST api/values
|
|
|
|
|
// POST api/champion
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public void Post([FromBody]int id, string name, string bio, string icon)
|
|
|
|
|
public ActionResult Post([FromBody]ChampionDTO? champion)
|
|
|
|
|
{
|
|
|
|
|
if (string.IsNullOrWhiteSpace(name) || string.IsNullOrWhiteSpace(bio) || string.IsNullOrWhiteSpace(icon)){
|
|
|
|
|
BadRequest();
|
|
|
|
|
if (champion == null){
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Ok();
|
|
|
|
|
championsManager.AddItem(champion.ToPoco());
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PUT api/values/5
|
|
|
|
|
[HttpPut("{id}")]
|
|
|
|
|
public void Put(int id, [FromBody]string value)
|
|
|
|
|
// PUT api/champion/5
|
|
|
|
|
[HttpPut("ChampionDto")]
|
|
|
|
|
public ActionResult Put([FromBody] ChampionDTO? champion, ChampionDTO? newChampion)
|
|
|
|
|
{
|
|
|
|
|
if (champion == null || newChampion == null)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
championsManager.UpdateItem(champion.ToPoco(), newChampion.ToPoco());
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// DELETE api/values/5
|
|
|
|
|
[HttpDelete("{id}")]
|
|
|
|
|
public void Delete(int id)
|
|
|
|
|
[HttpDelete("ChampionDto")]
|
|
|
|
|
public ActionResult Delete([FromBody] ChampionDTO? champion)
|
|
|
|
|
{
|
|
|
|
|
if (champion == null)
|
|
|
|
|
{
|
|
|
|
|
return BadRequest();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
championsManager.DeleteItem(champion.ToPoco());
|
|
|
|
|
return Ok();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|