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.
98 lines
2.7 KiB
98 lines
2.7 KiB
using API.Dto;
|
|
using API.Mapping;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Model;
|
|
using Newtonsoft.Json;
|
|
using StubLib;
|
|
using System.Collections.Generic;
|
|
using System.Net.Http;
|
|
using System.Net.Http.Headers;
|
|
using System.Net.Http.Json;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace API.Controllers
|
|
{
|
|
[ApiController]
|
|
[Route("[controller]")]
|
|
public class ChampionController : ControllerBase
|
|
{
|
|
private readonly ILogger<ChampionController> _logger;
|
|
private readonly StubData stub = 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;
|
|
|
|
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");
|
|
}
|
|
*/
|
|
|
|
/**** Méthodes GET ****/
|
|
[HttpGet]
|
|
public async Task<ActionResult<ChampionDto>> Get()
|
|
{
|
|
IEnumerable<Champion?> listeChamp = await stub.ChampionsMgr.GetItems(0, stub.ChampionsMgr.GetNbItems().Result);
|
|
|
|
List<ChampionDto> champs = new List<ChampionDto>();
|
|
|
|
listeChamp.ToList().ForEach(c => champs.Add(c.ToDto()));
|
|
return Ok(champs);
|
|
}
|
|
|
|
|
|
[HttpGet]
|
|
[Route("{id}")]
|
|
public ActionResult<IEnumerable<ChampionDto>> GetById()
|
|
{
|
|
BadRequest("404");
|
|
|
|
return Ok(Enumerable.Range(1, 5).Select(index => new ChampionDto
|
|
{
|
|
Id = index,
|
|
Name = "Stark",
|
|
Bio = "Trop fort",
|
|
})
|
|
.ToArray());
|
|
}
|
|
|
|
|
|
|
|
/*public async Task<IEnumerable<ChampionDto>> getJson()
|
|
{
|
|
var champions = await _client.GetFromJsonAsync<IEnumerable<ChampionDto>>();
|
|
var reponse = await _client.GetAsync("api/champion");
|
|
return champions;
|
|
}*/
|
|
|
|
/**** Méthodes POST ****/
|
|
|
|
|
|
/*[HttpPost]
|
|
public async Task<IActionResult> post([FromBody] ChampionDto champion)
|
|
{
|
|
return CreatedAtAction(nameof(GetById), new { id = 1 },
|
|
await dataManager.ChampionsMgr.AddItem(champion.ToModel));
|
|
}
|
|
|
|
public async void addchampion(ChampionDto champion)
|
|
{
|
|
_clientLpostAsJsonAscync<Champion>(ApiChampion, champion);
|
|
}*/
|
|
|
|
|
|
/**** Méthodes DELETE ****/
|
|
|
|
/**** Méthodes PUT ****/
|
|
|
|
}
|
|
}
|