pull/10/head
Louwar 2 years ago
parent 454e3e0aed
commit 7c03b5754f

@ -20,7 +20,8 @@ namespace API.Controllers
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 readonly IDataManager dataManager; // Pour plus tard pour le momment c'est avec le stub
// private const string Apichampion = "api/champion";
// private readonly HttpClient _client;
@ -29,54 +30,86 @@ namespace API.Controllers
_logger = logger;
}
/* public championHttpManager(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()
{
_client = client;
client.BaseAddress = new Uri("à chopper dans lauchSettings.json propriété du projet");
var champions = await _client.GetFromJsonAsync<IEnumerable<ChampionDto>>();
var reponse = await _client.GetAsync("api/champion");
return champions;
}
*/
*/
/**** Méthodes GET ****/
[HttpGet]
public async Task<ActionResult<ChampionDto>> Get()
public async Task<ActionResult<ChampionDto>> GetChamps()
{
IEnumerable<Champion?> listeChamp = await stub.ChampionsMgr.GetItems(0, stub.ChampionsMgr.GetNbItems().Result);
IEnumerable<Champion?> Champs = await stub.ChampionsMgr.GetItems(0, stub.ChampionsMgr.GetNbItems().Result);
List<ChampionDto> champs = new List<ChampionDto>();
List<ChampionDto> DtoChamps = new List<ChampionDto>();
listeChamp.ToList().ForEach(c => champs.Add(c.ToDto()));
return Ok(champs);
Champs.ToList().ForEach(c => DtoChamps.Add(c.ToDto()));
return Ok(DtoChamps);
}
[HttpGet]
[Route("{id}")]
public ActionResult<IEnumerable<ChampionDto>> GetById()
public async Task<ActionResult<ChampionDto>> GetChampByIdAsync(int id)
{
BadRequest("404");
return Ok(Enumerable.Range(1, 5).Select(index => new ChampionDto
IEnumerable<Champion?> Champs = await stub.ChampionsMgr.GetItems(id, 1);
if (id >= 0 && id < stub.ChampionsMgr.GetNbItems().Result)
{
Id = index,
Name = "Stark",
Bio = "Trop fort",
})
.ToArray());
return Ok(Champs.First().ToDto());
}
return BadRequest("404");
}
/*public async Task<IEnumerable<ChampionDto>> getJson()
[HttpGet("{id}/Skins")]
public async Task<ActionResult<SkinDto>> GetSkinsChamp(int id)
{
var champions = await _client.GetFromJsonAsync<IEnumerable<ChampionDto>>();
var reponse = await _client.GetAsync("api/champion");
return champions;
}*/
IEnumerable<Champion?> lcha = await stub.ChampionsMgr.GetItems(id, 1);
if (id >= 0 && id < stub.ChampionsMgr.GetNbItems().Result)
{
Champion ca = lcha.First();
IEnumerable<Skin?> lsk = await stub.SkinsMgr.GetItemsByChampion(ca, 0, stub.SkinsMgr.GetNbItemsByChampion(ca).Result);
List<SkinDto> skins = new List<SkinDto>();
lsk.ToList().ForEach(s => skins.Add(s.ToSkin()));
return Ok(skins);
}
return BadRequest();
}
/**** Méthodes POST ****/
[HttpPost("Ajouter/{nom}")]
public async Task<ActionResult> PostChampName(string nom)
{
Champion ca = new Champion(nom);
await donnees.ChampionsMgr.AddItem(ca);
return CreatedAtAction(nameof(GetChampId), new { id = donnees.ChampionsMgr.GetNbItems().Result - 1 }, ca.ChampToDto());
}
[HttpPost("Ajouter")]
public async Task<IActionResult> PostChamp([FromBody] ChampionDto c)
{
Champion ca = c.DtoToChamp();
await donnees.ChampionsMgr.AddItem(ca);
return CreatedAtAction(nameof(donnees.ChampionsMgr.GetItemsByName), new { Name = c.Name }, c);
}
/*[HttpPost]
[HttpPost]
public async Task<IActionResult> post([FromBody] ChampionDto champion)
{
return CreatedAtAction(nameof(GetById), new { id = 1 },
@ -86,12 +119,47 @@ namespace API.Controllers
public async void addchampion(ChampionDto champion)
{
_clientLpostAsJsonAscync<Champion>(ApiChampion, champion);
}*/
}
/**** Méthodes DELETE ****/
[HttpDelete("Supprimer/{id}")]
public async Task<IActionResult> DeleteChamp(int id)
{
IEnumerable<Champion?> lcha = await donnees.ChampionsMgr.GetItems(id, 1);
if (id >= 0 && id < donnees.ChampionsMgr.GetNbItems().Result)
{
Champion ca = lcha.First();
donnees.ChampionsMgr.DeleteItem(ca);
return Ok();
}
return BadRequest();
}
/**** Méthodes PUT ****/
}
[HttpPut("Modifier/{nom}")]// CA C4EST PAS FINI
public async Task<ActionResult> PutChampName(string nom)
{
Champion ca = new Champion(nom);
await donnees.ChampionsMgr.AddItem(ca);
return CreatedAtAction(nameof(GetChampId), new { id = donnees.ChampionsMgr.GetNbItems().Result - 1 }, ca.ChampToDto());
}
[HttpPut("Modifier")]
public async Task<IActionResult> PutChamp([FromBody] ChampionDto c, [FromBody] ChampionDto cNouv)
{
Champion ca = c.DtoToChamp();
Champion caNouv = cNouv.DtoToChamp();
await donnees.ChampionsMgr.UpdateItem(ca, caNouv);
return CreatedAtAction(nameof(GetChampId), new { id = donnees.ChampionsMgr.GetItems(0, donnees.ChampionsMgr.GetNbItems().Result).Result.ToList().IndexOf(ca) }, ca);
}
}
}

@ -2,12 +2,14 @@
{
public class ChampionDto
{
/**** Attributs ****/
/**** Only Attributs ****/
public int Id { get; set; }
public string Name { get; set; }
public string Bio { get; set; }
/**** Méthodes ****/
// Obliger de splti un dictionnaire pour le Json
public IEnumerable<string> Keydic { get; set; }
public IEnumerable<int> Valuedic { get; set; }
}
}

@ -0,0 +1,10 @@
namespace API.Dto
{
public class SkinDto
{
public string Name { get; set; }
public string Description { get; set; }
public string Icon { get; set; }
public float Price { get; set; }
}
}

@ -1,10 +1,6 @@
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
{
@ -12,52 +8,51 @@ namespace API.Mapping
{
public static ChampionDto ToDto(this Champion champion)
{
if(champion == null)
if (champion == null)
{
throw new ArgumentNullException("champion null");
}
return new ChampionDto
{
//Id = champion.Id,
Name = champion.Name, // je peux décider de mettre le nom en minuscule pour que le json est des noms en minuscule
Id = champion.Id,
Name = champion.Name, // je peux décider de mettre le nom en minuscule pour que le json est des noms en minuscule
Bio = champion.Bio,
Keydic = champion.Characteristics.Keys,
Valuedic = champion.Characteristics.Values
};
}
/*public static Champion ToModel(this ChampionDto championDto)
public static ChampionDto ToDto(this Champion champion)
{
if (championDto == null)
if (champion == null)
{
throw new ArgumentNullException("Dto null");
throw new ArgumentNullException("champion null");
}
return new Champion
return new ChampionDto
{
Name = championDto.Name,
Class = null,
Icon = null,
Image = null,
Bio = championDto.Bio,
Characteristics = null,
Skins = null,
Id = champion.Id,
Name = champion.Name, // je peux décider de mettre le nom en minuscule pour que le json est des noms en minuscule
Bio = champion.Bio,
Keydic = champion.Characteristics.Keys,
Valuedic = champion.Characteristics.Values
};
}*/
}
public static EFChampion ToEF(this ChampionDto championDto)
public static Champion ToSkin(this SkinDto skinDto)
{
if (championDto == null)
if (skinDto == null)
{
throw new ArgumentNullException("Dto null");
}
return new EFChampion
return new SkinDto()
{
Id = championDto.Id,
Name = championDto.Name,
Bio = championDto.Bio,
Icon = null,
};
Name = skinDto.Name,
Description = skinDto.Description,
Icon = skinDto.Icon,
Price = skinDto.Price
}
}
}
}

@ -2,7 +2,7 @@
{
public class EFChampion
{
/**** Attributs ****/
/**** Only Attributs ****/
public int Id { get; set; }
// https://learn.microsoft.com/fr-fr/ef/core/modeling/keyless-entity-types?tabs=data-annotations
@ -10,21 +10,5 @@
public string Bio { get; set; }
public string Icon { get; set; }
//public Dictionary<string, int> Characteristics { get; set; }
//public int this<string label>
/**** Méthodes ****/
public EFChampion()
{}
public EFChampion(int id, string name, string bio, string icon)
{
Id = id;
Name = name;
Bio = bio;
Icon = icon;
}
}
}

@ -23,9 +23,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "API", "API\API.csproj", "{3
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ConsoleAPI", "ConsoleAPI\ConsoleAPI.csproj", "{1BC3389F-495C-4889-8969-BD566F1512AF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "StubEF", "StubEF\StubEF.csproj", "{9AA1A21B-90EE-4D6C-B47B-8FDA701078EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject2", "TestProject2\TestProject2.csproj", "{48213B2E-9BFA-4735-852C-E4D401E7CED5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubEF", "StubEF\StubEF.csproj", "{9AA1A21B-90EE-4D6C-B47B-8FDA701078EF}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestEF", "TestEF\TestEF.csproj", "{84B0BF2B-17C8-403B-9A26-2310A2A368F9}"
EndProject
@ -71,10 +69,6 @@ Global
{9AA1A21B-90EE-4D6C-B47B-8FDA701078EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9AA1A21B-90EE-4D6C-B47B-8FDA701078EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9AA1A21B-90EE-4D6C-B47B-8FDA701078EF}.Release|Any CPU.Build.0 = Release|Any CPU
{48213B2E-9BFA-4735-852C-E4D401E7CED5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{48213B2E-9BFA-4735-852C-E4D401E7CED5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{48213B2E-9BFA-4735-852C-E4D401E7CED5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{48213B2E-9BFA-4735-852C-E4D401E7CED5}.Release|Any CPU.Build.0 = Release|Any CPU
{84B0BF2B-17C8-403B-9A26-2310A2A368F9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84B0BF2B-17C8-403B-9A26-2310A2A368F9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84B0BF2B-17C8-403B-9A26-2310A2A368F9}.Release|Any CPU.ActiveCfg = Release|Any CPU
@ -87,7 +81,6 @@ Global
{1889FA6E-B7C6-416E-8628-9449FB9070B9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB} = {2C607793-B163-4731-A4D1-AFE8A7C4C170}
{9AA1A21B-90EE-4D6C-B47B-8FDA701078EF} = {2C607793-B163-4731-A4D1-AFE8A7C4C170}
{48213B2E-9BFA-4735-852C-E4D401E7CED5} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
{84B0BF2B-17C8-403B-9A26-2310A2A368F9} = {C76D0C23-1FFA-4963-93CD-E12BD643F030}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution

@ -1,24 +0,0 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsPackable>false</IsPackable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
</Project>

@ -1,11 +0,0 @@
namespace TestProject2
{
public class UnitTest1
{
[Fact]
public void Test1()
{
}
}
}

@ -1 +0,0 @@
global using Xunit;
Loading…
Cancel
Save