diff --git a/Sources/WebApiLol/ChampionDTO.cs b/Sources/WebApiLol/ChampionDTO.cs index ca10c5b..6397ee0 100644 --- a/Sources/WebApiLol/ChampionDTO.cs +++ b/Sources/WebApiLol/ChampionDTO.cs @@ -3,6 +3,14 @@ namespace WebApiLol { public class ChampionDTO { + public ChampionDTO(string name, string bio, string icon, string championClassDTO) + { + Name = name; + Bio = bio; + Icon = icon; + Class = championClassDTO; + } + public int UniqueId { get; set; } public string Name { get; set; } @@ -10,6 +18,18 @@ namespace WebApiLol public string Bio { get; set; } public string Icon { get; set; } + + public string Class { get; set; } + + public bool equals(ChampionDTO other) + { + return other.Name == this.Name && other.Bio == this.Bio && other.Icon == this.Icon; + } + + public string toString() + { + return Name + Bio + Icon; + } } } diff --git a/Sources/WebApiLol/Controllers/ChampionController.cs b/Sources/WebApiLol/Controllers/ChampionController.cs index b463652..eac16fc 100644 --- a/Sources/WebApiLol/Controllers/ChampionController.cs +++ b/Sources/WebApiLol/Controllers/ChampionController.cs @@ -44,7 +44,7 @@ public class ChampionController : ControllerBase { champion.Bio = "Aucune bio"; } - Console.WriteLine("Le champion { " + champion.Name + " } avec pour bio { " + champion.Bio + " } a bien été ajouté"); + Console.WriteLine("Champion { " + champion.Name + " } with bio { " + champion.Bio + " } has been succesfully added"); return Ok(); } @@ -55,7 +55,7 @@ public class ChampionController : ControllerBase var existingChampion = championSelected.FirstOrDefault(); if (existingChampion == null) { - Console.WriteLine("Le champion { " + name + " } n'existe pas !"); + Console.WriteLine("Champion { " + name + " } doesn't exist !"); return NotFound(); } var updatedChampion = champion.toModel(); @@ -64,7 +64,7 @@ public class ChampionController : ControllerBase { updatedChampion.Bio = "Aucune bio"; } - Console.WriteLine("Le champion { " + name + " } a été modifié en { " + updatedChampion.Name + " } avec pour bio { " + updatedChampion.Bio + " }"); + Console.WriteLine("Champion { " + name + " } has been modified in { " + updatedChampion.Name + " } with bio { " + updatedChampion.Bio + " }"); return Ok(); } @@ -74,10 +74,10 @@ public class ChampionController : ControllerBase var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null); if (!await ChampionsManager.DeleteItem(championSelected.FirstOrDefault())) { - Console.WriteLine("champion { " + name + " } non trouvé !"); + Console.WriteLine("champion { " + name + " } not found !"); return NotFound(); } - Console.WriteLine("champion { " + name + " } supprimé"); + Console.WriteLine("champion { " + name + " } deleted"); return Ok(); } diff --git a/Sources/WebApiLol/Controllers/RuneController.cs b/Sources/WebApiLol/Controllers/RuneController.cs index b6e59fb..7fd1dd7 100644 --- a/Sources/WebApiLol/Controllers/RuneController.cs +++ b/Sources/WebApiLol/Controllers/RuneController.cs @@ -24,27 +24,68 @@ public class RuneController : ControllerBase _logger = logger; } - [HttpGet(Name = "GetRune")] - public ActionResult> Get() + [HttpGet] + public async Task Get() { - return Ok(Enumerable.Range(1,5).Select(index => new RuneDTO - { - Name = "La rune", - Description = "test description" - }) - .ToArray()); + var list = await RunesManager.GetItems(0, await RunesManager.GetNbItems()); + return Ok(list.Select(rune => rune?.toDTO())); + } + + [HttpGet("name")] + public async Task GetById(string name) + { + var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null); + return Ok(runeSelected.Select(rune => rune?.toDTO())); } - - [HttpPost] + + [HttpPost("addRune")] public async Task AddRune(RuneDTO rune) { var newRune = rune.toModel(); await RunesManager.AddItem(newRune); + if (rune.Description == "string") + { + rune.Description = "No bio"; + } + Console.WriteLine("Rune { " + rune.Name + " } with description { " + rune.Description + " } has been succesfully modified"); return Ok(newRune); } - + [HttpPut("updateRune")] + public async Task UpdateRune(string name, RuneDTO rune) + { + var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null); + var existingRune = runeSelected.FirstOrDefault(); + if (existingRune == null) + { + Console.WriteLine("La rune { " + name + " } doesn't exist !"); + return NotFound(); + } + var updatedRune = rune.toModel(); + await RunesManager.UpdateItem(existingRune, updatedRune); + if (rune.Description == "string") + { + rune.Description = "No bio"; + } + Console.WriteLine("Rune { " + name + " } has been succesfully modified { " + updatedRune.Name + " } with description { " + rune.Description + " }"); + return Ok(); + } + + [HttpDelete("deleteRune")] + public async Task DeleteRune(string name) + { + var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null); + if (!await RunesManager.DeleteItem(runeSelected.FirstOrDefault())) + { + Console.WriteLine("rune { " + name + " } not found !"); + return NotFound(); + } + Console.WriteLine("rune { " + name + " } deleted"); + return Ok(); + } + + } diff --git a/Sources/WebApiLol/Controllers/SkinController.cs b/Sources/WebApiLol/Controllers/SkinController.cs index d54398b..a089996 100644 --- a/Sources/WebApiLol/Controllers/SkinController.cs +++ b/Sources/WebApiLol/Controllers/SkinController.cs @@ -23,27 +23,67 @@ namespace WebApiLol.Controllers _logger = logger; } - [HttpGet(Name = "GetSkin")] - public ActionResult> Get() + [HttpGet] + public async Task Get() { - return Ok(Enumerable.Range(1, 5).Select(index => new SkinDTO - { - Name = "Skin tah les fou", - Description ="Skin assez limité et sorti le 23/02/2022", - Icon = "je sais pas ce que c'est un icon", - Price = 25.0f - }) - .ToArray()); + var list = await SkinsManager.GetItems(0, await SkinsManager.GetNbItems()); + return Ok(list.Select(skin => skin?.toDTO())); + } + + [HttpGet("name")] + public async Task GetById(string name) + { + var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null); + return Ok(skinSelected.Select(skin => skin?.toDTO())); } - [HttpPost] + [HttpPost("addSkin")] public async Task AddSkin(SkinDTO skin) { var newSkin = skin.toModel(); await SkinsManager.AddItem(newSkin); + if (skin.Description == "string") + { + skin.Description = "Aucune bio"; + } + Console.WriteLine("Skin { " + skin.Name + " } with description { " + skin.Description + " } has been succesfully added"); return Ok(newSkin); } + [HttpPut("updateSkin")] + public async Task UpdateChampion(string name, SkinDTO skin) + { + var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null); + var existingSkin = skinSelected.FirstOrDefault(); + if (existingSkin == null) + { + Console.WriteLine("Le skin { " + name + " } doesn't exist !"); + return NotFound(); + } + + var updatedSkin = skin.toModel(); + await SkinsManager.UpdateItem(existingSkin, updatedSkin); + if (skin.Description == "string") + { + skin.Description = "Aucune bio"; + } + Console.WriteLine("Skin { " + name + " } modified in " + " { " + updatedSkin.Name + " } with description { " + updatedSkin.Description + " }<"); + return Ok(); + } + + [HttpDelete("deleteSkin")] + public async Task DeleteChampion(string name) + { + var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null); + if (!await SkinsManager.DeleteItem(skinSelected.FirstOrDefault())) + { + Console.WriteLine("skin { " + name + " } not found !"); + return NotFound(); + } + Console.WriteLine("skin { " + name + " } deleted"); + return Ok(); + } + } } diff --git a/Sources/WebApiLol/Controllers/WeatherForecastController.cs b/Sources/WebApiLol/Controllers/WeatherForecastController.cs deleted file mode 100644 index 0e39eb8..0000000 --- a/Sources/WebApiLol/Controllers/WeatherForecastController.cs +++ /dev/null @@ -1,33 +0,0 @@ -//using Microsoft.AspNetCore.Mvc; - -//namespace WebApiLol.Controllers; - -//[ApiController] -//[Route("[controller]")] -//public class WeatherForecastController : ControllerBase -//{ -// private static readonly string[] Summaries = new[] -// { -// "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" -// }; - -// private readonly ILogger _logger; - -// public WeatherForecastController(ILogger logger) -// { -// _logger = logger; -// } - -// [HttpGet(Name = "GetWeatherForecast")] -// public IEnumerable<> Get() -// { -// return Enumerable.Range(1, 5).Select(index => new WeatherForecast -// { -// Date = DateOnly.FromDateTime(DateTime.Now.AddDays(index)), -// TemperatureC = Random.Shared.Next(-20, 55), -// Summary = Summaries[Random.Shared.Next(Summaries.Length)] -// }) -// .ToArray(); -// } -//} - diff --git a/Sources/WebApiLol/SkinDTO.cs b/Sources/WebApiLol/SkinDTO.cs index a357da0..4142b9a 100644 --- a/Sources/WebApiLol/SkinDTO.cs +++ b/Sources/WebApiLol/SkinDTO.cs @@ -7,6 +7,15 @@ namespace WebApiLol public string Description { get; set; } public string Icon { get; set; } public float Price { get; set; } - } + + public SkinDTO(string name, string description, string icon, float price) + { + Name = name; + Description = description; + Icon = icon; + Price = price; + + } + } }