From 55447bf403748a94c07f06e4c09f1350607bbc72 Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Wed, 15 Mar 2023 17:27:23 +0100 Subject: [PATCH] push --- .../APILOL/Controllers/ChampionsController.cs | 71 -------- Sources/APILOL/Mapper/ChampionMapper.cs | 3 +- Sources/APILOL/Mapper/SkillMapper.cs | 23 +++ Sources/DTO/ChampionDTO.cs | 3 +- Sources/DTO/SkillDTO.cs | 2 + Sources/EntityFrameworkLOL/Program.cs | 164 ------------------ 6 files changed, 27 insertions(+), 239 deletions(-) delete mode 100644 Sources/APILOL/Controllers/ChampionsController.cs create mode 100644 Sources/APILOL/Mapper/SkillMapper.cs diff --git a/Sources/APILOL/Controllers/ChampionsController.cs b/Sources/APILOL/Controllers/ChampionsController.cs deleted file mode 100644 index a64d8ca..0000000 --- a/Sources/APILOL/Controllers/ChampionsController.cs +++ /dev/null @@ -1,71 +0,0 @@ -using APILOL.Mapper; -using DTO; -using Microsoft.AspNetCore.Mvc; -using Model; -using StubLib; - -// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 - -namespace APILOL.Controllers -{ - [Route("api/[controller]")] - [ApiController] - public class ChampionsController : ControllerBase - { - IChampionsManager dataManager; - - public ChampionsController(IDataManager dataManager) - { - this.dataManager = dataManager.ChampionsMgr; - } - - - - // GET: api/ - [HttpGet] - public async Task Get(int index, int count) - { - var champions = await dataManager.GetItems(index, count); - IEnumerable items = champions.Select(c => c.ToDto()); - return Ok(items); - } - - // GET api//5 - [HttpGet("{name}")] - public async Task Get(string name) - { - if (dataManager.GetNbItemsByName(name) != null) - { - return Ok(dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems())); - } - return NotFound(); - } - - // POST api/ - [HttpPost] - public async Task Post([FromBody] ChampionDTO championDTO) - { - - return CreatedAtAction(nameof(Get),(await dataManager.AddItem(championDTO.ToModel())).ToDto); - } - - // PUT api//5 - [HttpPut("{name}")] - public async Task PutAsync(string name, [FromBody] ChampionDTO championDTO) - { - - var dtos = (await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems())); - - return Ok(dataManager.UpdateItem(dtos.First(), championDTO.ToModel())); - - } - - // DELETE api//5 - [HttpDelete("{name}")] - public async Task Delete(string name) - { - var dtos = (await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems())); - return Ok(dataManager.DeleteItem(dtos.First())); - } - } -} \ No newline at end of file diff --git a/Sources/APILOL/Mapper/ChampionMapper.cs b/Sources/APILOL/Mapper/ChampionMapper.cs index ecd6a18..cc5e8a8 100644 --- a/Sources/APILOL/Mapper/ChampionMapper.cs +++ b/Sources/APILOL/Mapper/ChampionMapper.cs @@ -15,8 +15,7 @@ namespace APILOL.Mapper Class = champion.Class, Icon = champion.Icon, Image = champion.Image, - Characteristics = champion.Characteristics, - Skills = champion.Skills, + Skills = champion.Skills.Select(skill => skill.ToDto()), }; } diff --git a/Sources/APILOL/Mapper/SkillMapper.cs b/Sources/APILOL/Mapper/SkillMapper.cs new file mode 100644 index 0000000..f8c0364 --- /dev/null +++ b/Sources/APILOL/Mapper/SkillMapper.cs @@ -0,0 +1,23 @@ +using DTO; +using Model; + +namespace APILOL.Mapper +{ + public static class SkillMapper + { + public static SkillDTO ToDto(this Skill skill) + { + return new SkillDTO() + { + Type = skill.Type, + Name = skill.Name, + Description = skill.Description + }; + } + + public static Skill ToModel(this SkillDTO skill) + { + return new Skill(skill.Name, skill.Type, skill.Description); + } + } +} diff --git a/Sources/DTO/ChampionDTO.cs b/Sources/DTO/ChampionDTO.cs index 12eb51f..82b6030 100644 --- a/Sources/DTO/ChampionDTO.cs +++ b/Sources/DTO/ChampionDTO.cs @@ -16,8 +16,7 @@ namespace DTO public LargeImage Image { get; set; } - public ReadOnlyDictionary Characteristics { get; set; } - public ImmutableHashSet Skills { get; set; } + public IEnumerable Skills { get; set; } } } \ No newline at end of file diff --git a/Sources/DTO/SkillDTO.cs b/Sources/DTO/SkillDTO.cs index 0f53f56..2b66a28 100644 --- a/Sources/DTO/SkillDTO.cs +++ b/Sources/DTO/SkillDTO.cs @@ -15,4 +15,6 @@ namespace DTO public string Description { get; set; } } + + } diff --git a/Sources/EntityFrameworkLOL/Program.cs b/Sources/EntityFrameworkLOL/Program.cs index 07c35d6..4fbb5ba 100644 --- a/Sources/EntityFrameworkLOL/Program.cs +++ b/Sources/EntityFrameworkLOL/Program.cs @@ -8,169 +8,5 @@ class Program { static void Main(string[] args) { - using (var context = new SQLiteContext()) { - if (context.Champion.Count() > 0) - { - foreach (var c in context.Champion.ToArray()) - { - context.Champion.Remove(c); - } - } - if (context.Rune.Count() > 0) - { - foreach (var r in context.Rune.ToArray()) - { - context.Rune.Remove(r); - } - } - if (context.Skin.Count() > 0) - { - foreach (var s in context.Skin.ToArray()) - { - context.Skin.Remove(s); - } - } - if (context.Skill.Count() > 0) - { - foreach (var s in context.Skill.ToArray()) - { - context.Skill.Remove(s); - } - } - if (context.RunePage.Count() > 0) - { - foreach (var rp in context.RunePage.ToArray()) - { - context.RunePage.Remove(rp); - } - } - if (context.ChampionClass.Count() > 0) - { - foreach (var cc in context.ChampionClass.ToArray()) - { - context.ChampionClass.Remove(cc); - } - } - if (context.RuneFamily.Count() > 0) - { - foreach (var rf in context.RuneFamily.ToArray()) - { - context.RuneFamily.Remove(rf); - } - } - if (context.SkillType.Count() > 0) - { - foreach (var st in context.SkillType.ToArray()) - { - context.SkillType.Remove(st); - } - } - if (context.Image.Count() > 0) - { - foreach (var i in context.Image.ToArray()) - { - context.Image.Remove(i); - } - } - context.SaveChanges(); - } - ChampionEntity akali = new ChampionEntity { Name = "Akali", Bio = "" }; - ChampionEntity aatrox = new ChampionEntity { Name = "Aatrox", Bio = "" }; - ChampionEntity ahri = new ChampionEntity { Name = "Ahri", Bio = "" }; - ChampionEntity bard = new ChampionEntity { Name = "Bard", Bio = "" }; - ChampionEntity alistar = new ChampionEntity { Name = "Alistar", Bio = "" }; - ChampionEntity akshan = new ChampionEntity { Name = "Akshan", Bio = "" }; - - using (var context = new SQLiteContext()) - { - // Crée des champions et les insère dans la base - Console.WriteLine("Creates and inserts new Champions"); - context.AddRange(new ChampionEntity[] { akali, aatrox, ahri, bard, alistar, akshan }); - /*context.Add(akali); - context.Add(aatrox); - context.Add(ahri); - context.Add(bard); - context.Add(alistar); - context.Add(akshan);*/ - context.SaveChanges(); - Console.WriteLine("Creates and executes a query retrieving the first Champion of the database whose name starts with an \"A\":"); - var aChampion = context.Champion - .Where(c => c.Name.StartsWith("A")) - .First(); - Console.WriteLine($"{aChampion.Name} (with bio : \"{aChampion.Bio}\")"); - } - - RuneEntity conqueror = new RuneEntity { Name = "Conqueror", Description = "" }; - RuneEntity thriumph = new RuneEntity { Name = "Thriumph", Description = "" }; - RuneEntity alacrity = new RuneEntity { Name = "Legend : Alacrity", Description = "" }; - RuneEntity tenacity = new RuneEntity { Name = "Legend : Tenacity", Description = "" }; - RuneEntity laststand = new RuneEntity { Name = "Last Stand", Description = "" }; - RuneEntity laststand2 = new RuneEntity { Name = "Last Stand 2", Description = "" }; - - using (var context = new SQLiteContext()) - { - // Crée des Runes et les insère dans la base - Console.WriteLine("Creates and inserts new Runes"); - context.AddRange(new RuneEntity[] { conqueror, thriumph, alacrity, tenacity, laststand, laststand2 }); - /*context.Add(conqueror); - context.Add(thriumph); - context.Add(alacrity); - context.Add(tenacity); - context.Add(laststand); - context.Add(laststand2);*/ - context.SaveChanges(); - Console.WriteLine("Creates and executes a query retrieving the first Runes of the database whose name starts with an \"L\":"); - var lRune = context.Rune - .Where(r => r.Name.StartsWith("L")) - .First(); - Console.WriteLine($"{lRune.Name} (with Description : \"{lRune.Description}\")"); - } - - SkinEntity stinger = new SkinEntity { Name = "Stinger", Description = "" }; - SkinEntity infernal = new SkinEntity { Name = "Infernal", Description = "" }; - SkinEntity allStar = new SkinEntity { Name = "All-Star", Description = "" }; - SkinEntity justicar = new SkinEntity { Name = "Justicar", Description = "" }; - SkinEntity mecha = new SkinEntity { Name = "Mecha", Description = "" }; - SkinEntity seaHunter = new SkinEntity { Name = "Sea Hunter", Description = "" }; - - using (var context = new SQLiteContext()) - { - // Crée des Skins et les insère dans la base - Console.WriteLine("Creates and inserts new Skins"); - context.AddRange(new SkinEntity[] { stinger, infernal, allStar, justicar, mecha, seaHunter }); - /*context.Add(stinger); - context.Add(infernal); - context.Add(allStar); - context.Add(justicar); - context.Add(mecha); - context.Add(seaHunter);*/ - context.SaveChanges(); - Console.WriteLine("Creates and executes a query retrieving the first Skins of the database whose name starts with an \"I\":"); - var iSkin = context.Skin - .Where(s => s.Name.StartsWith("I")) - .First(); - Console.WriteLine($"{iSkin.Name} (with Description : \"{iSkin.Description}\")"); - - Console.WriteLine("Updates the name of the Infernal Skin"); - iSkin.Description = "Hella Infernal (Wallah)"; - context.SaveChanges(); - Console.WriteLine($"{iSkin.Name} (with Description : \"{iSkin.Description}\")"); - - Console.WriteLine("Deletes one item from the database"); - var droid = context.Skin - .SingleOrDefault(s => s.Name.Equals("Infernal")); - context.Remove(droid); - context.SaveChanges(); - } - - using (var context = new SQLiteContext()) - { - foreach (var c in context.Champion) - { - c.Bio = $"{c.Name}"; - Console.WriteLine($"{c.Name} - {c.Bio}"); - } - context.SaveChanges(); - } } } \ No newline at end of file