From 1371e86c20dd39a8d841820acc01dfda2c7e71c5 Mon Sep 17 00:00:00 2001 From: Louwar Date: Wed, 15 Mar 2023 15:10:35 +0100 Subject: [PATCH 1/5] Update Manager --- Sources/EFManager/ManagerChampion.cs | 87 +++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 8 deletions(-) diff --git a/Sources/EFManager/ManagerChampion.cs b/Sources/EFManager/ManagerChampion.cs index 992c1e2..9c41a87 100644 --- a/Sources/EFManager/ManagerChampion.cs +++ b/Sources/EFManager/ManagerChampion.cs @@ -1,4 +1,5 @@ using EFlib; +using Microsoft.EntityFrameworkCore; using Microsoft.IdentityModel.Tokens; using Model; @@ -10,39 +11,109 @@ namespace EFManager public async Task AddItem(Champion? item) { - //await context.AddAsync(item.); TO DO + if (item == null) + return null; + + await context.AddAsync(item.toEF()); await context.SaveChangesAsync(); return item; } public Task DeleteItem(Champion? item) { - throw new NotImplementedException(); + if (item == null) + return false; + + context.Remove(item.toEF()); + await context.SaveChangesAsync(); + return true; } public Task> GetItems(int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + IQueryable query = Champions.Skip(index).Take(count); + + if (!string.IsNullOrEmpty(orderingPropertyName)) + { + query = descending ? + query.OrderByDescending(c => EF.Property(c, orderingPropertyName)) : + query.OrderBy(c => EF.Property(c, orderingPropertyName)); + } + + return await query.ToListAsync(); } public Task> GetItemsByCharacteristic(string charName, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + IQueryable query = Champions + .Where(c => c.Characteristics.ContainsKey(charName)) + .Skip(index) + .Take(count); + + if (!string.IsNullOrEmpty(orderingPropertyName)) + { + query = descending ? + query.OrderByDescending(c => EF.Property(c, orderingPropertyName)) : + query.OrderBy(c => EF.Property(c, orderingPropertyName)); + } + + return await query.ToListAsync(); + } public Task> GetItemsByClass(ChampionClass championClass, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + IQueryable query = Champions + .Where(c => c.Class == championClass) + .Skip(index) + .Take(count); + + if (!string.IsNullOrEmpty(orderingPropertyName)) + { + query = descending ? + query.OrderByDescending(c => EF.Property(c, orderingPropertyName)) : + query.OrderBy(c => EF.Property(c, orderingPropertyName)); + } + + return await query.ToListAsync(); } public Task> GetItemsByName(string substring, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + IQueryable query = Champions + .Where(c => c.Name.Contains(substring)) + .Skip(index) + .Take(count); + + if (!string.IsNullOrEmpty(orderingPropertyName)) + { + query = descending ? + query.OrderByDescending(c => EF.Property(c, orderingPropertyName)) : + query.OrderBy(c => EF.Property(c, orderingPropertyName)); + } + + return await query.ToListAsync(); } public Task> GetItemsByRunePage(RunePage? runePage, int index, int count, string? orderingPropertyName = null, bool descending = false) { - throw new NotImplementedException(); + IQueryable query = Champions; + + if (runePage != null) + { + query = query.Where(c => c.RunePageId == runePage.Id); + } + + query = query.Skip(index).Take(count); + + if (!string.IsNullOrEmpty(orderingPropertyName)) + { + query = descending ? + query.OrderByDescending(c => EF.Property(c, orderingPropertyName)) : + query.OrderBy(c => EF.Property(c, orderingPropertyName)); + } + + return await query.ToListAsync(); } public Task> GetItemsBySkill(Skill? skill, int index, int count, string? orderingPropertyName = null, bool descending = false) @@ -62,7 +133,7 @@ namespace EFManager public Task GetNbItemsByCharacteristic(string charName) { - throw new NotImplementedException(); + return await context.Where(c => c.Characteristics.Any(ch => ch.Name == charName)).CountAsync(); } public Task GetNbItemsByClass(ChampionClass championClass) From 12457f0a99af976ec1e64cfc1a12649726a39d9c Mon Sep 17 00:00:00 2001 From: Louwar Date: Wed, 15 Mar 2023 18:37:43 +0100 Subject: [PATCH 2/5] =?UTF-8?q?Update=20propri=C3=A9t=C3=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/API/Controllers/ChampionController.cs | 28 +++++++++------- Sources/API/Dto/ChampionDto.cs | 4 +-- Sources/API/Dto/SkillDto.cs | 11 +++++++ Sources/API/Dto/SkinDto.cs | 4 +-- Sources/API/Mapping/ChampionMapper.cs | 7 ++-- Sources/API/Mapping/SkillMapper.cs | 33 +++++++++++++++++++ Sources/API/Mapping/SkinMapper.cs | 8 ++--- Sources/EFlib/EFSkill.cs | 2 +- Sources/EFlib/EFSkin.cs | 7 ++-- 9 files changed, 80 insertions(+), 24 deletions(-) create mode 100644 Sources/API/Dto/SkillDto.cs create mode 100644 Sources/API/Mapping/SkillMapper.cs diff --git a/Sources/API/Controllers/ChampionController.cs b/Sources/API/Controllers/ChampionController.cs index 28f5012..31ee574 100644 --- a/Sources/API/Controllers/ChampionController.cs +++ b/Sources/API/Controllers/ChampionController.cs @@ -57,10 +57,10 @@ namespace API.Controllers [Route("{id}")] public async Task> GetChampById(int id) { - BadRequest("404"); - + // Récupération de la liste des champions IEnumerable Champs = await data.ChampionsMgr.GetItems(id, 1); + // Récupération du champion correspondant à l'id if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result) { return Ok(Champs.First().ToDto()); @@ -71,23 +71,23 @@ namespace API.Controllers [HttpGet("{id}/Skins")] public async Task> GetSkinsChamp(int id) { - // Récupération du champion - IEnumerable ChampNum = await data.ChampionsMgr.GetItems(id, 1); - + // Récupération de la liste des champions + IEnumerable Champs = await data.ChampionsMgr.GetItems(id, 1); + // Récupération du champion correspondant à l'id if (id >= 0 && id < data.ChampionsMgr.GetNbItems().Result) { // Converstion en Champion au lieu de champion IEnumerable - Champion champion = ChampNum.First(); + Champion champion = Champs.First(); // Récupération des skin du champion - IEnumerable ListeSkin = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result); + IEnumerable Skins = await data.SkinsMgr.GetItemsByChampion(champion, 0, data.SkinsMgr.GetNbItemsByChampion(champion).Result); // Création de la liste de skin List skins = new List(); - + // Ajout des skins dans la nouvelle liste - ListeSkin.ToList().ForEach(Skin => skins.Add(Skin.ToDto())); + Skins.ToList().ForEach(Skin => skins.Add(Skin.ToDto())); return Ok(skins); } @@ -98,23 +98,29 @@ namespace API.Controllers [HttpPost("Ajouter/{nom}")] public async Task PostChampName(string nom) { + // Création d'un champion avec son nom Champion champion = new Champion(nom); + // Ajout du champion dans la BD await data.ChampionsMgr.AddItem(champion); return CreatedAtAction(nameof(GetChampById), new { id = data.ChampionsMgr.GetNbItems().Result - 1 }, champion.ToDto()); } [HttpPost("Ajouter")] - public async Task PostChamp([FromBody] ChampionDto championDto) + public async Task PostChamp([FromBody] ChampionDto championDto) { + // Convertie le championDto en model (a était ajouté via l'API) Champion champion = championDto.ToModel(); + + // Ajout du champion en BD await data.ChampionsMgr.AddItem(champion); + return CreatedAtAction(nameof(data.ChampionsMgr.GetItemsByName), new { Name = championDto.Name }, championDto); } [HttpPost] - public async Task post([FromBody] ChampionDto championDto) + public async Task post([FromBody] ChampionDto championDto) { return CreatedAtAction(nameof(GetChampById), new { id = 1 }, await data.ChampionsMgr.AddItem(championDto.ToModel())); diff --git a/Sources/API/Dto/ChampionDto.cs b/Sources/API/Dto/ChampionDto.cs index 60f6fe5..e09dfa5 100644 --- a/Sources/API/Dto/ChampionDto.cs +++ b/Sources/API/Dto/ChampionDto.cs @@ -17,8 +17,8 @@ namespace API.Dto public IEnumerable Valuedic { get; set; } public ChampionClass Class { get; set; } - public ReadOnlyCollection Skins { get; set; } - public ImmutableHashSet Skills { get; private set; } + public ReadOnlyCollection Skins { get; set; } + public ImmutableHashSet Skills { get; private set; } public LargeImage Image { get; set; } } diff --git a/Sources/API/Dto/SkillDto.cs b/Sources/API/Dto/SkillDto.cs new file mode 100644 index 0000000..25757bf --- /dev/null +++ b/Sources/API/Dto/SkillDto.cs @@ -0,0 +1,11 @@ +using Model; + +namespace API.Dto +{ + public class SkillDto + { + public string Name { get; set; } + public string Description { get; set; } + public SkillType Type { get; set; } + } +} diff --git a/Sources/API/Dto/SkinDto.cs b/Sources/API/Dto/SkinDto.cs index 9e9f6d0..f4ebc41 100644 --- a/Sources/API/Dto/SkinDto.cs +++ b/Sources/API/Dto/SkinDto.cs @@ -5,10 +5,10 @@ namespace API.Dto public class SkinDto { public string Name { get; set; } - public Champion Champion { get; set; } + public ChampionDto Champion { get; set; } + public string Description { get; set; } public float Price { get; set; } public string Icon { get; set; } public LargeImage Image { get; set; } - public string Description { get; set; } } } diff --git a/Sources/API/Mapping/ChampionMapper.cs b/Sources/API/Mapping/ChampionMapper.cs index c1ad840..6cfafdb 100644 --- a/Sources/API/Mapping/ChampionMapper.cs +++ b/Sources/API/Mapping/ChampionMapper.cs @@ -21,11 +21,14 @@ namespace API.Mapping 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, Icon = champion.Icon, + Keydic = champion.Characteristics.Keys, Valuedic = champion.Characteristics.Values, + Class = champion.Class, - Image = champion.Image, - Skins = champion.Skins + Skins = champion.Skins, + Skills = champion.Skills, + Image = champion.Image }; } public static Champion ToModel(this ChampionDto champion) diff --git a/Sources/API/Mapping/SkillMapper.cs b/Sources/API/Mapping/SkillMapper.cs new file mode 100644 index 0000000..06be263 --- /dev/null +++ b/Sources/API/Mapping/SkillMapper.cs @@ -0,0 +1,33 @@ +using API.Dto; +using Model; + +namespace API.Mapping +{ + public static class SkillMapper + { + public static SkillDto ToDto(this Skill skill) + { + if (skill == null) + { + throw new ArgumentNullException("Skill null"); + } + + return new SkillDto() + { + Name = skill.Name, + Description = skill.Description, + Type = skill.Type + }; + } + + public static Skill ToSkill(this SkillDto skillDto) + { + if (skillDto == null) + { + throw new ArgumentNullException("SkinDto null"); + } + + return new Skill(skillDto.Name, skillDto.Type, skillDto.Description); + } + } +} diff --git a/Sources/API/Mapping/SkinMapper.cs b/Sources/API/Mapping/SkinMapper.cs index 9ef0014..7066a64 100644 --- a/Sources/API/Mapping/SkinMapper.cs +++ b/Sources/API/Mapping/SkinMapper.cs @@ -16,11 +16,11 @@ namespace API.Mapping return new SkinDto() { Name = skin.Name, - Champion = skin.Champion, + Champion = skin.Champion.ToDto(), + Description = skin.Description, Price = skin.Price, Icon = skin.Icon, - Image = skin.Image, - Description = skin.Description + Image = skin.Image }; } @@ -31,7 +31,7 @@ namespace API.Mapping throw new ArgumentNullException("SkinDto null"); } - return new Skin(skinDto.Name, skinDto.Champion, skinDto.Price, skinDto.Icon, skinDto.Image.Base64, skinDto.Description); + return new Skin(skinDto.Name, skinDto.Champion.ToModel(), skinDto.Price, skinDto.Icon, skinDto.Image.Base64, skinDto.Description); } } } diff --git a/Sources/EFlib/EFSkill.cs b/Sources/EFlib/EFSkill.cs index 7af417f..14ea1fc 100644 --- a/Sources/EFlib/EFSkill.cs +++ b/Sources/EFlib/EFSkill.cs @@ -11,6 +11,6 @@ namespace EFlib { public string Name { get; set; } public string Description { get; set; } - public SkillType SkillType { get; set; } + public SkillType Type { get; set; } } } diff --git a/Sources/EFlib/EFSkin.cs b/Sources/EFlib/EFSkin.cs index 76488da..d42d767 100644 --- a/Sources/EFlib/EFSkin.cs +++ b/Sources/EFlib/EFSkin.cs @@ -1,13 +1,16 @@ -namespace EFlib +using Model; + +namespace EFlib { public class EFSkin { /**** Attributs ****/ public string Name { get; set; } + public EFChampion champion { get; set; } public string Description { get; set; } public string Icon { get; set; } public float Price { get; set; } - public EFChampion champion { get; set; } + public LargeImage Image { get; set; } } } From eb07f9c1945dc7bca650dc30713e866b9047b6b8 Mon Sep 17 00:00:00 2001 From: Louwar Date: Wed, 15 Mar 2023 19:31:19 +0100 Subject: [PATCH 3/5] Update Class project --- Sources/API/Controllers/ChampionController.cs | 50 ++++++++++--------- Sources/API/Controllers/RuneController.cs | 6 +++ Sources/API/Controllers/RunePageController.cs | 6 +++ Sources/API/Controllers/SkillController.cs | 6 +++ Sources/API/Controllers/SkinController.cs | 6 +++ Sources/API/Dto/RuneDto.cs | 6 +++ Sources/API/Dto/RunePageDto.cs | 6 +++ Sources/API/Mapping/RuneMapper.cs | 6 +++ Sources/API/Mapping/RunePageMapper.cs | 6 +++ Sources/EFManager/ManagerRune.cs | 12 +++++ 10 files changed, 87 insertions(+), 23 deletions(-) create mode 100644 Sources/API/Controllers/RuneController.cs create mode 100644 Sources/API/Controllers/RunePageController.cs create mode 100644 Sources/API/Controllers/SkillController.cs create mode 100644 Sources/API/Controllers/SkinController.cs create mode 100644 Sources/API/Dto/RuneDto.cs create mode 100644 Sources/API/Dto/RunePageDto.cs create mode 100644 Sources/API/Mapping/RuneMapper.cs create mode 100644 Sources/API/Mapping/RunePageMapper.cs create mode 100644 Sources/EFManager/ManagerRune.cs diff --git a/Sources/API/Controllers/ChampionController.cs b/Sources/API/Controllers/ChampionController.cs index 31ee574..a39521e 100644 --- a/Sources/API/Controllers/ChampionController.cs +++ b/Sources/API/Controllers/ChampionController.cs @@ -10,32 +10,43 @@ namespace API.Controllers [Route("[controller]")] public class ChampionController : ControllerBase { - private readonly ILogger _logger; private readonly StubData data = 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; + // Pour plus tard pour le momment c'est avec le stub + // private readonly IDataManager dataManager; + + private readonly ILogger _logger; public ChampionController(ILogger logger) { _logger = logger; } - /* public championHttpManager(HttpClient client) - { - _client = client; - client.BaseAddress = new Uri("à chopper dans lauchSettings.json propriété du projet"); - } + /* + + private const string Apichampion = "api/champion"; + private readonly HttpClient _client; + + public championHttpManager(HttpClient client) + { + + _client = client; + client.BaseAddress = new Uri("à chopper dans lauchSettings.json propriété du projet"); + } + + public async Task> getJson() + { + var champions = await _client.GetFromJsonAsync>(); + var reponse = await _client.GetAsync("api/champion"); + return champions; + } - public async Task> getJson() + public async void addchampion(ChampionDto champion) { - var champions = await _client.GetFromJsonAsync>(); - var reponse = await _client.GetAsync("api/champion"); - return champions; - }*/ - + _clientLpostAsJsonAscync(ApiChampion, champion); + } + */ + /**** Méthodes GET ****/ [HttpGet] @@ -126,12 +137,6 @@ namespace API.Controllers await data.ChampionsMgr.AddItem(championDto.ToModel())); } - /*public async void addchampion(ChampionDto champion) - { - _clientLpostAsJsonAscync(ApiChampion, champion); - } -*/ - /**** Méthodes DELETE ****/ [HttpDelete("Supprimer/{id}")] @@ -149,7 +154,6 @@ namespace API.Controllers } - /**** Méthodes PUT ****/ [HttpPut("Modifier/{nom}")] diff --git a/Sources/API/Controllers/RuneController.cs b/Sources/API/Controllers/RuneController.cs new file mode 100644 index 0000000..9c3b717 --- /dev/null +++ b/Sources/API/Controllers/RuneController.cs @@ -0,0 +1,6 @@ +namespace API.Controllers +{ + public class RuneController + { + } +} diff --git a/Sources/API/Controllers/RunePageController.cs b/Sources/API/Controllers/RunePageController.cs new file mode 100644 index 0000000..34dde7d --- /dev/null +++ b/Sources/API/Controllers/RunePageController.cs @@ -0,0 +1,6 @@ +namespace API.Controllers +{ + public class RunePageController + { + } +} diff --git a/Sources/API/Controllers/SkillController.cs b/Sources/API/Controllers/SkillController.cs new file mode 100644 index 0000000..853575b --- /dev/null +++ b/Sources/API/Controllers/SkillController.cs @@ -0,0 +1,6 @@ +namespace API.Controllers +{ + public class SkillController + { + } +} diff --git a/Sources/API/Controllers/SkinController.cs b/Sources/API/Controllers/SkinController.cs new file mode 100644 index 0000000..3f7f919 --- /dev/null +++ b/Sources/API/Controllers/SkinController.cs @@ -0,0 +1,6 @@ +namespace API.Controllers +{ + public class SkinController + { + } +} diff --git a/Sources/API/Dto/RuneDto.cs b/Sources/API/Dto/RuneDto.cs new file mode 100644 index 0000000..b1cefc5 --- /dev/null +++ b/Sources/API/Dto/RuneDto.cs @@ -0,0 +1,6 @@ +namespace API.Dto +{ + public class RuneDto + { + } +} diff --git a/Sources/API/Dto/RunePageDto.cs b/Sources/API/Dto/RunePageDto.cs new file mode 100644 index 0000000..daf20cb --- /dev/null +++ b/Sources/API/Dto/RunePageDto.cs @@ -0,0 +1,6 @@ +namespace API.Dto +{ + public class RunePageDto + { + } +} diff --git a/Sources/API/Mapping/RuneMapper.cs b/Sources/API/Mapping/RuneMapper.cs new file mode 100644 index 0000000..5315396 --- /dev/null +++ b/Sources/API/Mapping/RuneMapper.cs @@ -0,0 +1,6 @@ +namespace API.Mapping +{ + public class RuneMapper + { + } +} diff --git a/Sources/API/Mapping/RunePageMapper.cs b/Sources/API/Mapping/RunePageMapper.cs new file mode 100644 index 0000000..3a21079 --- /dev/null +++ b/Sources/API/Mapping/RunePageMapper.cs @@ -0,0 +1,6 @@ +namespace API.Mapping +{ + public class RunePageMapper + { + } +} diff --git a/Sources/EFManager/ManagerRune.cs b/Sources/EFManager/ManagerRune.cs new file mode 100644 index 0000000..ab1d5eb --- /dev/null +++ b/Sources/EFManager/ManagerRune.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace EFManager +{ + internal class ManagerRune + { + } +} From 1898a85c5d9d7d2c96a299bcac60c0fcb14c1f1e Mon Sep 17 00:00:00 2001 From: Louwar Date: Fri, 17 Mar 2023 08:16:22 +0100 Subject: [PATCH 4/5] Delete SQL ServerContexte --- Sources/EFlib/EFlib.csproj | 1 - Sources/EFlib/SqlServerContext.cs | 16 ---------------- 2 files changed, 17 deletions(-) delete mode 100644 Sources/EFlib/SqlServerContext.cs diff --git a/Sources/EFlib/EFlib.csproj b/Sources/EFlib/EFlib.csproj index 330fd62..0550ea3 100644 --- a/Sources/EFlib/EFlib.csproj +++ b/Sources/EFlib/EFlib.csproj @@ -13,7 +13,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Sources/EFlib/SqlServerContext.cs b/Sources/EFlib/SqlServerContext.cs deleted file mode 100644 index 1477e49..0000000 --- a/Sources/EFlib/SqlServerContext.cs +++ /dev/null @@ -1,16 +0,0 @@ -using Microsoft.EntityFrameworkCore; - - -namespace EFlib -{ - internal class SqlServerContext : DbContext - { - /**** Attributs ****/ - public DbSet Champions { get; set; } - /**** Méthodes ****/ - protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) - { - optionsBuilder.UseSqlServer($"@\"Server=(localdb)\\mssqllocaldb;Database=projet.dbloulou.mdf;"); - } - } -} From ee0562a9b3ba841afb83e5323027c817f59f0838 Mon Sep 17 00:00:00 2001 From: Louwar Date: Fri, 17 Mar 2023 08:19:36 +0100 Subject: [PATCH 5/5] =?UTF-8?q?Update=20d=C3=A9pendance?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/Consoles/ConsoleTests/ConsoleTests.csproj | 1 - Sources/Model/Model.csproj | 1 - Sources/Shared/Shared.csproj | 1 - Sources/Stubs/StubLib/StubLib.csproj | 1 - 4 files changed, 4 deletions(-) diff --git a/Sources/Consoles/ConsoleTests/ConsoleTests.csproj b/Sources/Consoles/ConsoleTests/ConsoleTests.csproj index 1825fdd..e753e2d 100644 --- a/Sources/Consoles/ConsoleTests/ConsoleTests.csproj +++ b/Sources/Consoles/ConsoleTests/ConsoleTests.csproj @@ -17,7 +17,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Sources/Model/Model.csproj b/Sources/Model/Model.csproj index 4f22210..d0ef6ce 100644 --- a/Sources/Model/Model.csproj +++ b/Sources/Model/Model.csproj @@ -15,7 +15,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Sources/Shared/Shared.csproj b/Sources/Shared/Shared.csproj index fc454d5..b364c9d 100644 --- a/Sources/Shared/Shared.csproj +++ b/Sources/Shared/Shared.csproj @@ -9,7 +9,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/Sources/Stubs/StubLib/StubLib.csproj b/Sources/Stubs/StubLib/StubLib.csproj index 3eb1871..534bd51 100644 --- a/Sources/Stubs/StubLib/StubLib.csproj +++ b/Sources/Stubs/StubLib/StubLib.csproj @@ -9,7 +9,6 @@ - all runtime; build; native; contentfiles; analyzers; buildtransitive