|
|
|
@ -10,32 +10,43 @@ namespace API.Controllers
|
|
|
|
|
[Route("[controller]")]
|
|
|
|
|
public class ChampionController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<ChampionController> _logger;
|
|
|
|
|
private readonly StubData data = new StubData();
|
|
|
|
|
|
|
|
|
|
private readonly IDataManager dataManager; // Pour plus tard pour le momment c'est avec le stub
|
|
|
|
|
|
|
|
|
|
private const string Apichampion = "api/champion";
|
|
|
|
|
private readonly HttpClient _client;
|
|
|
|
|
// Pour plus tard pour le momment c'est avec le stub
|
|
|
|
|
// private readonly IDataManager dataManager;
|
|
|
|
|
|
|
|
|
|
private readonly ILogger<ChampionController> _logger;
|
|
|
|
|
|
|
|
|
|
public ChampionController(ILogger<ChampionController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* public championHttpManager(HttpClient client)
|
|
|
|
|
{
|
|
|
|
|
_client = client;
|
|
|
|
|
client.BaseAddress = new Uri("à chopper dans lauchSettings.json propriété du projet");
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
|
|
private const string Apichampion = "api/champion";
|
|
|
|
|
private readonly HttpClient _client;
|
|
|
|
|
|
|
|
|
|
public championHttpManager(HttpClient client)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
_client = client;
|
|
|
|
|
client.BaseAddress = new Uri("à chopper dans lauchSettings.json propriété du projet");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<ChampionDto>> getJson()
|
|
|
|
|
{
|
|
|
|
|
var champions = await _client.GetFromJsonAsync<IEnumerable<ChampionDto>>();
|
|
|
|
|
var reponse = await _client.GetAsync("api/champion");
|
|
|
|
|
return champions;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task<IEnumerable<ChampionDto>> getJson()
|
|
|
|
|
public async void addchampion(ChampionDto champion)
|
|
|
|
|
{
|
|
|
|
|
var champions = await _client.GetFromJsonAsync<IEnumerable<ChampionDto>>();
|
|
|
|
|
var reponse = await _client.GetAsync("api/champion");
|
|
|
|
|
return champions;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|
_clientLpostAsJsonAscync<Champion>(ApiChampion, champion);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**** Méthodes GET ****/
|
|
|
|
|
[HttpGet]
|
|
|
|
@ -57,10 +68,10 @@ namespace API.Controllers
|
|
|
|
|
[Route("{id}")]
|
|
|
|
|
public async Task<ActionResult<ChampionDto>> GetChampById(int id)
|
|
|
|
|
{
|
|
|
|
|
BadRequest("404");
|
|
|
|
|
|
|
|
|
|
// Récupération de la liste des champions
|
|
|
|
|
IEnumerable<Champion?> Champs = await data.ChampionsMgr.GetItems(id, 1);
|
|
|
|
|
|
|
|
|
|
// Récupération du champion correspondant à l'id
|
|
|
|
|
if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result)
|
|
|
|
|
{
|
|
|
|
|
return Ok(Champs.First().ToDto());
|
|
|
|
@ -71,23 +82,23 @@ namespace API.Controllers
|
|
|
|
|
[HttpGet("{id}/Skins")]
|
|
|
|
|
public async Task<ActionResult<SkinDto>> GetSkinsChamp(int id)
|
|
|
|
|
{
|
|
|
|
|
// Récupération du champion
|
|
|
|
|
IEnumerable<Champion?> ChampNum = await data.ChampionsMgr.GetItems(id, 1);
|
|
|
|
|
|
|
|
|
|
// Récupération de la liste des champions
|
|
|
|
|
IEnumerable<Champion?> Champs = await data.ChampionsMgr.GetItems(id, 1);
|
|
|
|
|
|
|
|
|
|
// Récupération du champion correspondant à l'id
|
|
|
|
|
if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result)
|
|
|
|
|
{
|
|
|
|
|
// Converstion en Champion au lieu de champion IEnumerable
|
|
|
|
|
Champion champion = ChampNum.First();
|
|
|
|
|
Champion champion = Champs.First();
|
|
|
|
|
|
|
|
|
|
// Récupération des skin du champion
|
|
|
|
|
IEnumerable<Skin?> ListeSkin = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result);
|
|
|
|
|
IEnumerable<Skin?> Skins = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result);
|
|
|
|
|
|
|
|
|
|
// Création de la liste de skin
|
|
|
|
|
List<SkinDto> skins = new List<SkinDto>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ajout des skins dans la nouvelle liste
|
|
|
|
|
ListeSkin.ToList().ForEach(Skin => skins.Add(Skin.ToDto()));
|
|
|
|
|
Skins.ToList().ForEach(Skin => skins.Add(Skin.ToDto()));
|
|
|
|
|
|
|
|
|
|
return Ok(skins);
|
|
|
|
|
}
|
|
|
|
@ -98,34 +109,34 @@ namespace API.Controllers
|
|
|
|
|
[HttpPost("Ajouter/{nom}")]
|
|
|
|
|
public async Task<ActionResult> PostChampName(string nom)
|
|
|
|
|
{
|
|
|
|
|
// Création d'un champion avec son nom
|
|
|
|
|
Champion champion = new Champion(nom);
|
|
|
|
|
|
|
|
|
|
// Ajout du champion dans la BD
|
|
|
|
|
await data.ChampionsMgr.AddItem(champion);
|
|
|
|
|
|
|
|
|
|
return CreatedAtAction(nameof(GetChampById), new { id = data.ChampionsMgr.GetNbItems().Result - 1 }, champion.ToDto());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost("Ajouter")]
|
|
|
|
|
public async Task<IActionResult> PostChamp([FromBody] ChampionDto championDto)
|
|
|
|
|
public async Task<ActionResult> PostChamp([FromBody] ChampionDto championDto)
|
|
|
|
|
{
|
|
|
|
|
// Convertie le championDto en model (a était ajouté via l'API)
|
|
|
|
|
Champion champion = championDto.ToModel();
|
|
|
|
|
|
|
|
|
|
// Ajout du champion en BD
|
|
|
|
|
await data.ChampionsMgr.AddItem(champion);
|
|
|
|
|
|
|
|
|
|
return CreatedAtAction(nameof(data.ChampionsMgr.GetItemsByName), new { Name = championDto.Name }, championDto);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[HttpPost]
|
|
|
|
|
public async Task<IActionResult> post([FromBody] ChampionDto championDto)
|
|
|
|
|
public async Task<ActionResult> post([FromBody] ChampionDto championDto)
|
|
|
|
|
{
|
|
|
|
|
return CreatedAtAction(nameof(GetChampById), new { id = 1 },
|
|
|
|
|
await data.ChampionsMgr.AddItem(championDto.ToModel()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*public async void addchampion(ChampionDto champion)
|
|
|
|
|
{
|
|
|
|
|
_clientLpostAsJsonAscync<Champion>(ApiChampion, champion);
|
|
|
|
|
}
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**** Méthodes DELETE ****/
|
|
|
|
|
|
|
|
|
|
[HttpDelete("Supprimer/{id}")]
|
|
|
|
@ -143,7 +154,6 @@ namespace API.Controllers
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**** Méthodes PUT ****/
|
|
|
|
|
|
|
|
|
|
[HttpPut("Modifier/{nom}")]
|
|
|
|
|