Added Champions Controller

EF_Entity_DB
Emre KARTAL 2 years ago
parent 87c49b8b24
commit b7670ae160

Binary file not shown.

@ -2,5 +2,6 @@
"ExpandedNodes": [
""
],
"SelectedNode": "\\LeagueOfLegends.sln",
"PreviewInSolutionExplorer": false
}

@ -10,4 +10,10 @@
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.3" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DTO\DTO.csproj" />
<ProjectReference Include="..\Model\Model.csproj" />
<ProjectReference Include="..\StubLib\StubLib.csproj" />
</ItemGroup>
</Project>

@ -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/<ValuesController>
[HttpGet]
public async Task<IActionResult> 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/<ValuesController>/5
[HttpGet("{name}")]
public IActionResult Get(string name)
{
dataManager.GetItemsByName(name, 0, 1);
return NotFound();
}
// POST api/<ValuesController>
[HttpPost]
public async Task<IActionResult> Post([FromBody] ChampionDto value)
{
//await dataManager.AddItem(value.toModel());
return Ok();
}
// PUT api/<ValuesController>/5
[HttpPut("{id}")]
public void Put(int id, [FromBody] string value)
{
}
// DELETE api/<ValuesController>/5
[HttpDelete("{id}")]
public void Delete(int id)
{
}
}
}

@ -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<WeatherForecast> 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),

@ -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,
};
}
}
}

@ -0,0 +1,7 @@
namespace DTO
{
public class ChampionDto
{
public string Name { get; set; }
}
}

@ -0,0 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
</Project>

@ -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

@ -1,151 +1,151 @@
using System.Collections.Immutable;
using System.Collections.ObjectModel;
using System.Numerics;
using System.Text;
namespace Model;
public class Champion : IEquatable<Champion>
{
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<string, int>(characteristics);
Skins = new ReadOnlyCollection<Skin>(skins);
}
public ReadOnlyCollection<Skin> Skins { get; private set; }
private List<Skin> skins = new ();
public ReadOnlyDictionary<string, int> Characteristics { get; private set; }
private readonly Dictionary<string, int> characteristics = new Dictionary<string, int>();
public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
private HashSet<Skill> skills = new HashSet<Skill>();
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<string, int>[] 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<Champion>
{
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<string, int>(characteristics);
Skins = new ReadOnlyCollection<Skin>(skins);
}
public ReadOnlyCollection<Skin> Skins { get; private set; }
private List<Skin> skins = new ();
public ReadOnlyDictionary<string, int> Characteristics { get; private set; }
private readonly Dictionary<string, int> characteristics = new Dictionary<string, int>();
public ImmutableHashSet<Skill> Skills => skills.ToImmutableHashSet();
private HashSet<Skill> skills = new HashSet<Skill>();
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<string, int>[] 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();
}
}

Loading…
Cancel
Save