🔨 add CRUD operation for rune, champion and skin
continuous-integration/drone/push Build is failing Details

api_lol
Maxence LANONE 2 years ago
parent 2abbcb5663
commit 10979b13e8

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

@ -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();
}

@ -24,27 +24,68 @@ public class RuneController : ControllerBase
_logger = logger;
}
[HttpGet(Name = "GetRune")]
public ActionResult<IEnumerable<RuneDTO>> Get()
[HttpGet]
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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();
}
}

@ -23,27 +23,67 @@ namespace WebApiLol.Controllers
_logger = logger;
}
[HttpGet(Name = "GetSkin")]
public ActionResult<IEnumerable<SkinDTO>> Get()
[HttpGet]
public async Task<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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<IActionResult> 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();
}
}
}

@ -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<WeatherForecastController> _logger;
// public WeatherForecastController(ILogger<WeatherForecastController> 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();
// }
//}

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

Loading…
Cancel
Save