diff --git a/Sources/API/Controllers/ChampionController.cs b/Sources/API/Controllers/ChampionController.cs index 72e09be..4dc8005 100644 --- a/Sources/API/Controllers/ChampionController.cs +++ b/Sources/API/Controllers/ChampionController.cs @@ -20,7 +20,8 @@ namespace API.Controllers private readonly ILogger _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> getJson() { - _client = client; - client.BaseAddress = new Uri("à chopper dans lauchSettings.json propriété du projet"); + var champions = await _client.GetFromJsonAsync>(); + var reponse = await _client.GetAsync("api/champion"); + return champions; } -*/ + */ /**** Méthodes GET ****/ [HttpGet] - public async Task> Get() + public async Task> GetChamps() { - IEnumerable listeChamp = await stub.ChampionsMgr.GetItems(0, stub.ChampionsMgr.GetNbItems().Result); + IEnumerable Champs = await stub.ChampionsMgr.GetItems(0, stub.ChampionsMgr.GetNbItems().Result); - List champs = new List(); + List DtoChamps = new List(); - 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> GetById() + public async Task> GetChampByIdAsync(int id) { BadRequest("404"); - return Ok(Enumerable.Range(1, 5).Select(index => new ChampionDto + IEnumerable 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> getJson() + [HttpGet("{id}/Skins")] + public async Task> GetSkinsChamp(int id) { - var champions = await _client.GetFromJsonAsync>(); - var reponse = await _client.GetAsync("api/champion"); - return champions; - }*/ + IEnumerable lcha = await stub.ChampionsMgr.GetItems(id, 1); + + if (id >= 0 && id < stub.ChampionsMgr.GetNbItems().Result) + { + Champion ca = lcha.First(); + + IEnumerable lsk = await stub.SkinsMgr.GetItemsByChampion(ca, 0, stub.SkinsMgr.GetNbItemsByChampion(ca).Result); + + List skins = new List(); + lsk.ToList().ForEach(s => skins.Add(s.ToSkin())); + return Ok(skins); + } + return BadRequest(); + } + /**** Méthodes POST ****/ + [HttpPost("Ajouter/{nom}")] + public async Task 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 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 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(ApiChampion, champion); - }*/ - + } + /**** Méthodes DELETE ****/ + [HttpDelete("Supprimer/{id}")] + public async Task DeleteChamp(int id) + { + IEnumerable 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 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 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); + } + + } } diff --git a/Sources/API/Dto/ChampionDto.cs b/Sources/API/Dto/ChampionDto.cs index 421f1ee..8756c51 100644 --- a/Sources/API/Dto/ChampionDto.cs +++ b/Sources/API/Dto/ChampionDto.cs @@ -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 Keydic { get; set; } + public IEnumerable Valuedic { get; set; } + } } diff --git a/Sources/API/Dto/SkinDto.cs b/Sources/API/Dto/SkinDto.cs new file mode 100644 index 0000000..097551a --- /dev/null +++ b/Sources/API/Dto/SkinDto.cs @@ -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; } + } +} diff --git a/Sources/API/Mapping/ChampionMapper.cs b/Sources/API/Mapping/ChampionMapper.cs index c204e4f..fde70fb 100644 --- a/Sources/API/Mapping/ChampionMapper.cs +++ b/Sources/API/Mapping/ChampionMapper.cs @@ -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 + } } } } diff --git a/Sources/EFlib/EFChampion.cs b/Sources/EFlib/EFChampion.cs index 7a344ad..6ebc39b 100644 --- a/Sources/EFlib/EFChampion.cs +++ b/Sources/EFlib/EFChampion.cs @@ -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 Characteristics { get; set; } - //public int this - - /**** Méthodes ****/ - public EFChampion() - {} - public EFChampion(int id, string name, string bio, string icon) - { - Id = id; - Name = name; - Bio = bio; - Icon = icon; - } - - } } \ No newline at end of file diff --git a/Sources/LeagueOfLegends.sln b/Sources/LeagueOfLegends.sln index 5665c80..19996b0 100644 --- a/Sources/LeagueOfLegends.sln +++ b/Sources/LeagueOfLegends.sln @@ -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 diff --git a/Sources/TestProject2/TestProject2.csproj b/Sources/TestProject2/TestProject2.csproj deleted file mode 100644 index c5d1063..0000000 --- a/Sources/TestProject2/TestProject2.csproj +++ /dev/null @@ -1,24 +0,0 @@ - - - - net6.0 - enable - enable - - false - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - diff --git a/Sources/TestProject2/UnitTest1.cs b/Sources/TestProject2/UnitTest1.cs deleted file mode 100644 index 2e7a3d1..0000000 --- a/Sources/TestProject2/UnitTest1.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace TestProject2 -{ - public class UnitTest1 - { - [Fact] - public void Test1() - { - - } - } -} \ No newline at end of file diff --git a/Sources/TestProject2/Usings.cs b/Sources/TestProject2/Usings.cs deleted file mode 100644 index 8c927eb..0000000 --- a/Sources/TestProject2/Usings.cs +++ /dev/null @@ -1 +0,0 @@ -global using Xunit; \ No newline at end of file