|
|
|
@ -18,15 +18,15 @@ namespace API.Controllers
|
|
|
|
|
public class ChampionController : ControllerBase
|
|
|
|
|
{
|
|
|
|
|
private readonly ILogger<ChampionController> _logger;
|
|
|
|
|
private readonly HttpClient _client;
|
|
|
|
|
private readonly IDataManager dataManager;
|
|
|
|
|
private readonly StubData stub = new StubData();
|
|
|
|
|
|
|
|
|
|
private const string Apichampion = "api/champion";
|
|
|
|
|
// 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(IDataManager datamanager, ILogger<ChampionController> logger)
|
|
|
|
|
public ChampionController(ILogger<ChampionController> logger)
|
|
|
|
|
{
|
|
|
|
|
_logger = logger;
|
|
|
|
|
this.dataManager = datamanager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* public championHttpManager(HttpClient client)
|
|
|
|
@ -40,8 +40,6 @@ namespace API.Controllers
|
|
|
|
|
[HttpGet]
|
|
|
|
|
public async Task<ActionResult<ChampionDto>> Get()
|
|
|
|
|
{
|
|
|
|
|
StubData stub = new StubData();
|
|
|
|
|
|
|
|
|
|
IEnumerable<Champion?> listeChamp = await stub.ChampionsMgr.GetItems(0, stub.ChampionsMgr.GetNbItems().Result);
|
|
|
|
|
|
|
|
|
|
List<ChampionDto> champs = new List<ChampionDto>();
|
|
|
|
@ -66,40 +64,12 @@ namespace API.Controllers
|
|
|
|
|
.ToArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static async Task GetJsonData()
|
|
|
|
|
{
|
|
|
|
|
using var client = new HttpClient();
|
|
|
|
|
client.BaseAddress = new Uri("https://localhost:7175");
|
|
|
|
|
client.DefaultRequestHeaders.Accept.Clear();
|
|
|
|
|
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
|
|
|
|
|
|
|
|
|
|
HttpResponseMessage response = await client.GetAsync("/api/ChampionDto");
|
|
|
|
|
if (response.IsSuccessStatusCode)
|
|
|
|
|
{
|
|
|
|
|
var responseBody = await response.Content.ReadAsStringAsync();
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var champions = JsonConvert.DeserializeObject<List<ChampionDto>>(responseBody);
|
|
|
|
|
if (champions != null)
|
|
|
|
|
{
|
|
|
|
|
foreach (var champion in champions)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine($"Name: {champion.Name}, Bio: {champion.Bio}");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
Console.ReadLine();
|
|
|
|
|
}
|
|
|
|
|
catch (JsonReaderException)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Something went wrong.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*public async Task<IEnumerable<ChampionDto>> getJson()
|
|
|
|
|
{
|
|
|
|
|
var champions = await _client.GetFromJsonAsync<IEnumerable<ChampionDto>>();
|
|
|
|
|
var reponse = await _cleint.GetAscyn("api/champion");
|
|
|
|
|
var reponse = await _client.GetAsync("api/champion");
|
|
|
|
|
return champions;
|
|
|
|
|
}*/
|
|
|
|
|
|
|
|
|
|