diff --git a/.vs/LolProject/v17/.suo b/.vs/LolProject/v17/.suo index 52cf1a5..d3190ef 100644 Binary files a/.vs/LolProject/v17/.suo and b/.vs/LolProject/v17/.suo differ diff --git a/.vs/VSWorkspaceState.json b/.vs/VSWorkspaceState.json index 9568b22..9c530b2 100644 --- a/.vs/VSWorkspaceState.json +++ b/.vs/VSWorkspaceState.json @@ -2,5 +2,6 @@ "ExpandedNodes": [ "" ], + "SelectedNode": "\\LeagueOfLegends.sln", "PreviewInSolutionExplorer": false } \ No newline at end of file diff --git a/src/EntityFramework_LoL/Sources/ApiLol/ApiLol.csproj b/src/EntityFramework_LoL/Sources/ApiLol/ApiLol.csproj index 4289e82..e9239f1 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/ApiLol.csproj +++ b/src/EntityFramework_LoL/Sources/ApiLol/ApiLol.csproj @@ -10,4 +10,10 @@ + + + + + + diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs new file mode 100644 index 0000000..c19a41a --- /dev/null +++ b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs @@ -0,0 +1,52 @@ +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 = new StubData().ChampionsMgr; + // GET: api/ + [HttpGet] + public async Task Get() + { + var champions = await dataManager.GetItems(0, await dataManager.GetNbItems()); // Le await va permettre que les lignes suivantes ne s'éxécute pas + return Ok(new { result = champions.Select(c => c.ToDto())}); + } + + // GET api//5 + [HttpGet("{name}")] + public IActionResult Get(string name) + { + dataManager.GetItemsByName(name, 0, 1); + return NotFound(); + } + + // POST api/ + [HttpPost] + public async Task Post([FromBody] ChampionDto value) + { + //await dataManager.AddItem(value.toModel()); + return Ok(); + } + + // PUT api//5 + [HttpPut("{id}")] + public void Put(int id, [FromBody] string value) + { + } + + // DELETE api//5 + [HttpDelete("{id}")] + public void Delete(int id) + { + } + } +} diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/WeatherForecastController.cs b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/WeatherForecastController.cs index 3c0f0e8..cf9e709 100644 --- a/src/EntityFramework_LoL/Sources/ApiLol/Controllers/WeatherForecastController.cs +++ b/src/EntityFramework_LoL/Sources/ApiLol/Controllers/WeatherForecastController.cs @@ -1,4 +1,6 @@ +using ApiLol.Mapper; using Microsoft.AspNetCore.Mvc; +using Model; namespace ApiLol.Controllers { @@ -21,6 +23,13 @@ namespace ApiLol.Controllers [HttpGet(Name = "GetWeatherForecast")] public IEnumerable Get() { + /* + var champion = new Champion(""); + + //var dtop = ChampionMapper.ToDto(champion); + + var dto = champion.ToDto();*/ + return Enumerable.Range(1, 5).Select(index => new WeatherForecast { Date = DateTime.Now.AddDays(index), diff --git a/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs new file mode 100644 index 0000000..e56f46d --- /dev/null +++ b/src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs @@ -0,0 +1,16 @@ +using DTO; +using Model; + +namespace ApiLol.Mapper +{ + public static class ChampionMapper + { + public static ChampionDto ToDto(this Champion champion) + { + return new ChampionDto() + { + Name = champion.Name, + }; + } + } +} diff --git a/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs b/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs new file mode 100644 index 0000000..5c7ecf2 --- /dev/null +++ b/src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs @@ -0,0 +1,7 @@ +namespace DTO +{ + public class ChampionDto + { + public string Name { get; set; } + } +} \ No newline at end of file diff --git a/src/EntityFramework_LoL/Sources/DTO/DTO.csproj b/src/EntityFramework_LoL/Sources/DTO/DTO.csproj new file mode 100644 index 0000000..bafd05b --- /dev/null +++ b/src/EntityFramework_LoL/Sources/DTO/DTO.csproj @@ -0,0 +1,9 @@ + + + + net6.0 + enable + enable + + + diff --git a/src/EntityFramework_LoL/Sources/LeagueOfLegends.sln b/src/EntityFramework_LoL/Sources/LeagueOfLegends.sln index d877689..df59485 100644 --- a/src/EntityFramework_LoL/Sources/LeagueOfLegends.sln +++ b/src/EntityFramework_LoL/Sources/LeagueOfLegends.sln @@ -15,7 +15,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Stub", "Stub", "{2C607793-B EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StubLib", "StubLib\StubLib.csproj", "{B01D7EF2-2D64-409A-A29A-61FB7BB7A9DB}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ApiLol", "ApiLol\ApiLol.csproj", "{D59C9C7B-9BC2-4601-959D-BFA97E46D017}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ApiLol", "ApiLol\ApiLol.csproj", "{D59C9C7B-9BC2-4601-959D-BFA97E46D017}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DTO", "DTO\DTO.csproj", "{3919E408-EB12-4422-989B-C6ED4816D465}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -43,6 +45,10 @@ Global {D59C9C7B-9BC2-4601-959D-BFA97E46D017}.Debug|Any CPU.Build.0 = Debug|Any CPU {D59C9C7B-9BC2-4601-959D-BFA97E46D017}.Release|Any CPU.ActiveCfg = Release|Any CPU {D59C9C7B-9BC2-4601-959D-BFA97E46D017}.Release|Any CPU.Build.0 = Release|Any CPU + {3919E408-EB12-4422-989B-C6ED4816D465}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3919E408-EB12-4422-989B-C6ED4816D465}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3919E408-EB12-4422-989B-C6ED4816D465}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3919E408-EB12-4422-989B-C6ED4816D465}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/EntityFramework_LoL/Sources/Model/Champion.cs b/src/EntityFramework_LoL/Sources/Model/Champion.cs index 3a50658..b8b369b 100644 --- a/src/EntityFramework_LoL/Sources/Model/Champion.cs +++ b/src/EntityFramework_LoL/Sources/Model/Champion.cs @@ -1,151 +1,151 @@ using System.Collections.Immutable; using System.Collections.ObjectModel; using System.Numerics; -using System.Text; - -namespace Model; -public class Champion : IEquatable -{ - public string Name - { - get => name; - private init - { - if(string.IsNullOrWhiteSpace(value)) - { - name = "Unknown"; - return; - } - name = value; - } - } - private readonly string name = null!; - - public string Bio - { - get => bio; - set - { - if(value == null) - { - bio = ""; - return; - } - bio = value; - } - } - private string bio = ""; - - public ChampionClass Class { get; set; } - - public string Icon { get; set; } - - public LargeImage Image { get; set; } - - public Champion(string name, ChampionClass champClass = ChampionClass.Unknown, string icon = "", string image = "", string bio = "") - { - Name = name; - Class = champClass; - Icon = icon; - Image = new LargeImage(image); - Bio = bio; - Characteristics = new ReadOnlyDictionary(characteristics); - Skins = new ReadOnlyCollection(skins); - } - - public ReadOnlyCollection Skins { get; private set; } - private List skins = new (); - - public ReadOnlyDictionary Characteristics { get; private set; } - private readonly Dictionary characteristics = new Dictionary(); - - public ImmutableHashSet Skills => skills.ToImmutableHashSet(); - private HashSet skills = new HashSet(); - - internal bool AddSkin(Skin skin) - { - if (skins.Contains(skin)) - return false; - skins.Add(skin); - return true; - } - - internal bool RemoveSkin(Skin skin) - => skins.Remove(skin); - - public bool AddSkill(Skill skill) - => skills.Add(skill); - - public bool RemoveSkill(Skill skill) - => skills.Remove(skill); - - public void AddCharacteristics(params Tuple[] someCharacteristics) - { - foreach(var c in someCharacteristics) - { - characteristics[c.Item1] = c.Item2; - } - } - - public bool RemoveCharacteristics(string label) - => characteristics.Remove(label); - - public int? this[string label] - { - get - { - if(!characteristics.TryGetValue(label, out int value)) return null; - else return value; - } - set - { - if(!value.HasValue) - { - RemoveCharacteristics(label); - return; - } - characteristics[label] = value.Value; - } - } - - public override bool Equals(object? obj) - { - if(ReferenceEquals(obj, null)) return false; - if(ReferenceEquals(obj, this)) return true; - if(GetType() != obj.GetType()) return false; - return Equals(obj as Champion); - } - - public override int GetHashCode() - => Name.GetHashCode() % 997; - - public bool Equals(Champion? other) - => Name.Equals(other?.Name); - - public override string ToString() - { - StringBuilder sb = new StringBuilder($"{Name} ({Class})"); - if(!string.IsNullOrWhiteSpace(bio)) - { - sb.AppendLine($"\t{bio}"); - } - if(characteristics.Any()) - { - sb.AppendLine("\tCharacteristics:"); - foreach(var characteristic in characteristics) - { - sb.AppendLine($"\t\t{characteristic.Key} - {characteristic.Value}"); - } - } - if(skills.Any()) - { - sb.AppendLine("\tSkills:"); - foreach(var skill in Skills) - { - sb.AppendLine($"\t\t{skill.Name} - {skill.Description}"); - } - } - return sb.ToString(); - } -} - +using System.Text; + +namespace Model; +public class Champion : IEquatable +{ + public string Name + { + get => name; + private init + { + if(string.IsNullOrWhiteSpace(value)) + { + name = "Unknown"; + return; + } + name = value; + } + } + private readonly string name = null!; + + public string Bio + { + get => bio; + set + { + if(value == null) + { + bio = ""; + return; + } + bio = value; + } + } + private string bio = ""; + + public ChampionClass Class { get; set; } + + public string Icon { get; set; } + + public LargeImage Image { get; set; } + + public Champion(string name, ChampionClass champClass = ChampionClass.Unknown, string icon = "", string image = "", string bio = "") + { + Name = name; + Class = champClass; + Icon = icon; + Image = new LargeImage(image); + Bio = bio; + Characteristics = new ReadOnlyDictionary(characteristics); + Skins = new ReadOnlyCollection(skins); + } + + public ReadOnlyCollection Skins { get; private set; } + private List skins = new (); + + public ReadOnlyDictionary Characteristics { get; private set; } + private readonly Dictionary characteristics = new Dictionary(); + + public ImmutableHashSet Skills => skills.ToImmutableHashSet(); + private HashSet skills = new HashSet(); + + internal bool AddSkin(Skin skin) + { + if (skins.Contains(skin)) + return false; + skins.Add(skin); + return true; + } + + internal bool RemoveSkin(Skin skin) + => skins.Remove(skin); + + public bool AddSkill(Skill skill) + => skills.Add(skill); + + public bool RemoveSkill(Skill skill) + => skills.Remove(skill); + + public void AddCharacteristics(params Tuple[] someCharacteristics) + { + foreach(var c in someCharacteristics) + { + characteristics[c.Item1] = c.Item2; + } + } + + public bool RemoveCharacteristics(string label) + => characteristics.Remove(label); + + public int? this[string label] + { + get + { + if(!characteristics.TryGetValue(label, out int value)) return null; + else return value; + } + set + { + if(!value.HasValue) + { + RemoveCharacteristics(label); + return; + } + characteristics[label] = value.Value; + } + } + + public override bool Equals(object? obj) + { + if(ReferenceEquals(obj, null)) return false; + if(ReferenceEquals(obj, this)) return true; + if(GetType() != obj.GetType()) return false; + return Equals(obj as Champion); + } + + public override int GetHashCode() + => Name.GetHashCode() % 997; + + public bool Equals(Champion? other) + => Name.Equals(other?.Name); + + public override string ToString() + { + StringBuilder sb = new StringBuilder($"{Name} ({Class})"); + if(!string.IsNullOrWhiteSpace(bio)) + { + sb.AppendLine($"\t{bio}"); + } + if(characteristics.Any()) + { + sb.AppendLine("\tCharacteristics:"); + foreach(var characteristic in characteristics) + { + sb.AppendLine($"\t\t{characteristic.Key} - {characteristic.Value}"); + } + } + if(skills.Any()) + { + sb.AppendLine("\tSkills:"); + foreach(var skill in Skills) + { + sb.AppendLine($"\t\t{skill.Name} - {skill.Description}"); + } + } + return sb.ToString(); + } +} +