pull/10/head
Louwar 2 years ago
parent 6e3ceb6d58
commit 4bbc32febf

@ -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;
}*/

@ -1,5 +1,10 @@
using API.Dto;
using EFlib;
using Model;
using static System.Net.Mime.MediaTypeNames;
using System.Collections.ObjectModel;
using System.Reflection.PortableExecutable;
using System.Security.Claims;
namespace API.Mapping
{
@ -20,7 +25,7 @@ namespace API.Mapping
};
}
/*public static Champion ToChampion(this ChampionDto championDto)
/*public static Champion ToModel(this ChampionDto championDto)
{
if (championDto == null)
{
@ -29,11 +34,30 @@ namespace API.Mapping
return new Champion
{
Id = championDto.Id,
Name = championDto.Name,
Class = null,
Icon = null,
Image = null,
Bio = championDto.Bio,
Icon = null
Characteristics = null,
Skins = null,
};
}*/
public static EntityChampion ToEF(this ChampionDto championDto)
{
if (championDto == null)
{
throw new ArgumentNullException("Dto null");
}
return new EntityChampion
{
Id = championDto.Id,
Name = championDto.Name,
Bio = championDto.Bio,
Icon = null,
};
}
}
}

@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
 <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
@ -7,4 +7,12 @@
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="13.0.2" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\API\API.csproj" />
</ItemGroup>
</Project>

@ -1,4 +1,8 @@
// See https://aka.ms/new-console-template for more information
using API.Dto;
using Newtonsoft.Json;
using System.Net.Http.Headers;
Console.WriteLine("Hello, World!");
using (var client = new HttpClient())
@ -6,3 +10,33 @@ using (var client = new HttpClient())
var response = await client.GetAsync("https://www.example.com");
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
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.");
}
}
}
Loading…
Cancel
Save