Compare commits

...

2 Commits

Author SHA1 Message Date
Maxence LANONE a63b866b27 🚧 mise en place liaison bdd et api
continuous-integration/drone/push Build is failing Details
2 years ago
Maxence LANONE 10979b13e8 🔨 add CRUD operation for rune, champion and skin
continuous-integration/drone/push Build is failing Details
2 years ago

@ -61,11 +61,7 @@ namespace DbDatamanager
throw new NotImplementedException();
}
public async Task<int> GetNbItems()
{
var nbItems = lolContext.Champions.Count();
return nbItems;
}
public async Task<int> GetNbItems() => lolContext.Champions.Count();
private Func<Champion, string, bool> filterByName = (champ, substring) => champ.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase);

@ -3,6 +3,7 @@ namespace WebApiLol
{
public class ChampionDTO
{
public int UniqueId { get; set; }
public string Name { get; set; }
@ -10,6 +11,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;
}
}
}

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Model;
using StubLib;
using WebApiLol.Converter;
@ -12,26 +13,29 @@ namespace WebApiLol.Controllers;
[Route("[controller]")]
public class ChampionController : ControllerBase
{
private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData());
//private StubData.ChampionsManager ChampionManager { get; set; } = new StubData.ChampionManager(new StubData());
private readonly ILogger<ChampionController> _logger;
public ChampionController(ILogger<ChampionController> logger)
private IChampionsManager _dataManager;
public ChampionController(ILogger<ChampionController> logger, IDataManager dataManager)
{
_logger = logger;
_dataManager = dataManager.ChampionsMgr;
}
[HttpGet]
public async Task<IActionResult> Get()
{
var list = await ChampionsManager.GetItems(0, await ChampionsManager.GetNbItems());
var list = await _dataManager.GetItems(0, await _dataManager.GetNbItems());
return Ok(list.Select(champion => champion?.toDTO()));
}
[HttpGet("name")]
public async Task<IActionResult> GetById(string name)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
var championSelected = await _dataManager.GetItemsByName(name, 0, await _dataManager.GetNbItemsByName(name), null);
return Ok(championSelected.Select(c => c?.toDTO()));
}
@ -39,45 +43,45 @@ public class ChampionController : ControllerBase
public async Task<IActionResult> AddChampion([FromBody] ChampionDTO champion)
{
var newChampion = champion.toModel();
await ChampionsManager.AddItem(newChampion);
await _dataManager.AddItem(newChampion);
if (champion.Bio == "string")
{
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();
}
[HttpPut("Update")]
public async Task<IActionResult> UpdateChampion(string name, [FromBody] ChampionDTO champion)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
var championSelected = await _dataManager.GetItemsByName(name, 0, await _dataManager.GetNbItemsByName(name), null);
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();
await ChampionsManager.UpdateItem(existingChampion, updatedChampion);
await _dataManager.UpdateItem(existingChampion, updatedChampion);
if (updatedChampion.Bio == "string")
{
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();
}
[HttpDelete("Delete")]
public async Task<IActionResult> DeleteChampion(string name)
{
var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null);
if (!await ChampionsManager.DeleteItem(championSelected.FirstOrDefault()))
var championSelected = await _dataManager.GetItemsByName(name, 0, await _dataManager.GetNbItemsByName(name), null);
if (!await _dataManager.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();
// }
//}

@ -8,6 +8,8 @@ namespace WebApiLol.Converter
{
Name = champion.Name,
Bio = champion.Bio,
Icon = champion.Icon,
Class = champion.Class.ToString()
};
public static Champion toModel(this ChampionDTO champion) => new Champion(champion.Name, champion.Bio);

@ -9,6 +9,8 @@ namespace WebApiLol.Converter
{
Name = skin.Name,
Description = skin.Description,
Icon = skin.Icon,
Price = skin.Price
};
public static Skin toModel(this SkinDTO skin) => new Skin(skin.Name, skin.Description);

@ -1,5 +1,8 @@
var builder = WebApplication.CreateBuilder(args);
using DbDatamanager;
using Model;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddScoped<IDataManager, DbDataManager>();
// Add services to the container.
builder.Services.AddControllers();
@ -7,6 +10,7 @@ builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
var app = builder.Build();
// Configure the HTTP request pipeline.

@ -7,6 +7,6 @@ namespace WebApiLol
public string Description { get; set; }
public string Icon { get; set; }
public float Price { get; set; }
}
}
}

@ -11,7 +11,7 @@
<PropertyGroup Condition=" '$(RunConfiguration)' == 'https' " />
<PropertyGroup Condition=" '$(RunConfiguration)' == 'http' " />
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.3" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="7.0.4" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
@ -28,5 +28,11 @@
<ProjectReference Include="..\StubLib\StubLib.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
<ProjectReference Include="..\EntityFrameWorkLib\EntityFrameWorkLib.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
<ProjectReference Include="..\DbDatamanager\DbDatamanager.csproj">
<GlobalPropertiesToRemove></GlobalPropertiesToRemove>
</ProjectReference>
</ItemGroup>
</Project>

Loading…
Cancel
Save