From b7670ae16063f02800fc4b3007b46368bd3c3db6 Mon Sep 17 00:00:00 2001 From: emkartal1 Date: Fri, 27 Jan 2023 17:38:27 +0100 Subject: [PATCH] Added Champions Controller --- .vs/LolProject/v17/.suo | Bin 11264 -> 13824 bytes .vs/VSWorkspaceState.json | 1 + .../Sources/ApiLol/ApiLol.csproj | 6 + .../ApiLol/Controllers/ChampionsController.cs | 52 +++ .../Controllers/WeatherForecastController.cs | 9 + .../Sources/ApiLol/Mapper/ChampionMapper.cs | 16 + .../Sources/DTO/ChampionDto.cs | 7 + .../Sources/DTO/DTO.csproj | 9 + .../Sources/LeagueOfLegends.sln | 8 +- .../Sources/Model/Champion.cs | 296 +++++++++--------- 10 files changed, 255 insertions(+), 149 deletions(-) create mode 100644 src/EntityFramework_LoL/Sources/ApiLol/Controllers/ChampionsController.cs create mode 100644 src/EntityFramework_LoL/Sources/ApiLol/Mapper/ChampionMapper.cs create mode 100644 src/EntityFramework_LoL/Sources/DTO/ChampionDto.cs create mode 100644 src/EntityFramework_LoL/Sources/DTO/DTO.csproj diff --git a/.vs/LolProject/v17/.suo b/.vs/LolProject/v17/.suo index 52cf1a557d8d01f20140b2c18a661ea33a24c6b4..d3190eff2d84debdc910ff8157ca8d8816dcad71 100644 GIT binary patch delta 1587 zcmcIk%}*0i5Z||K=~{MS`$_3mE479~EVkH&B|<`Cqr_GU!Gj)*g544$ek9$hAtvsD z1TQAIllXriCleA$;K0r3!RXz@lZgbIKuo}yr47Xpm4nmHzTMxO_vSbAW}bP?oLLxT zj>Vxio=MQjM_N~wH!n@~eP%%p#R;?gEK{M%kHRXS0y8MUlcv11i^AhPjo=Q%xa$5lrMzO+C}Y+t-J$1Fb2!ZxMv zD;r0r#6nPYMj$Kt{C?cFt>&v8NAipQ+TG-s2oSl0zFlEZTtX+Yq{&9L+14=k(opy< zvyNtcVnl4IIi}pP090BF61l=%ZLwiLR9i=7=0iNtU=Bvxn4N!$gsjOJR)T_kOYKWjj#u*(uCO50D&Q!tPQI2#D8H4Tao9d$GNNA1N_Z!Wp0d{ zB{K2O8ARm@;Bv zrEW!Yvc1Z?zd8m#qG4F*O4~W4O01^{R#buc;Ej3-TyYuXct6a=2f>W@oo8saFO+9G zmDoV3G>|T)(uvYksxOhAOiv{=O;09ttuK@5Pia~)Q-p7E6-K%>815d1Brn2xw`N7N z64jswweGzkj7Cy_3FA~6*7#(N`L;V}2cWyhbB*&zui$c&udTCbs(jk0bSckWM@_Zr5655Zo% aNj_O2pA`z)Pkh1uI*6)fsjuLp+Vcz1FD11A delta 1032 zcmb_bzi-n}5YBU)A2rX8+t~ThxJ^@#Ky8F*(?}qJNFYO`M5Nu?i42Sk46#&oiN(s2 z`eR~2Ow3VMBq}vXY`_M8NF*W<;m;TjzoB`874x!LVkD236& z{qkKrP2H2snp1>$jOSRzbn}}?V6xtk*#Ha!L>%trevBueVp?d)Je_z|VF0`}6^Bk+ z^6r*HV9&mW8Uf#(CdSGQ^j1FT5$2x@Be=ods^?dU;A&eI0)LoRMBx_usO=D3Y>vDQ zPoQhpP}}zLap$^U`ApX`;ntkK$G&}YMyOHs3E%K@HD7anx06v_drSLJ|I-{r8k6)h zD&IiEenX`j7~6ea%s<=NPI)MYnKs4_4JGTq%vN;4Z;Tgl-n<64(2@Lz!he82j`6}R lOiL}vkK 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(); + } +} +