diff --git a/Sources/DbDatamanager/ChampionManager.cs b/Sources/DbDatamanager/ChampionManager.cs index 1f97fe9..52bd318 100644 --- a/Sources/DbDatamanager/ChampionManager.cs +++ b/Sources/DbDatamanager/ChampionManager.cs @@ -61,11 +61,7 @@ namespace DbDatamanager throw new NotImplementedException(); } - public async Task GetNbItems() - { - var nbItems = lolContext.Champions.Count(); - return nbItems; - } + public async Task GetNbItems() => lolContext.Champions.Count(); private Func filterByName = (champ, substring) => champ.Name.Contains(substring, StringComparison.InvariantCultureIgnoreCase); diff --git a/Sources/WebApiLol/ChampionDTO.cs b/Sources/WebApiLol/ChampionDTO.cs index 6397ee0..12e85a9 100644 --- a/Sources/WebApiLol/ChampionDTO.cs +++ b/Sources/WebApiLol/ChampionDTO.cs @@ -3,13 +3,6 @@ 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; } diff --git a/Sources/WebApiLol/Controllers/ChampionController.cs b/Sources/WebApiLol/Controllers/ChampionController.cs index eac16fc..a408590 100644 --- a/Sources/WebApiLol/Controllers/ChampionController.cs +++ b/Sources/WebApiLol/Controllers/ChampionController.cs @@ -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 _logger; - public ChampionController(ILogger logger) + private IChampionsManager _dataManager; + + public ChampionController(ILogger logger, IDataManager dataManager) { _logger = logger; + _dataManager = dataManager.ChampionsMgr; } [HttpGet] public async Task 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 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,7 +43,7 @@ public class ChampionController : ControllerBase public async Task AddChampion([FromBody] ChampionDTO champion) { var newChampion = champion.toModel(); - await ChampionsManager.AddItem(newChampion); + await _dataManager.AddItem(newChampion); if (champion.Bio == "string") { champion.Bio = "Aucune bio"; @@ -51,7 +55,7 @@ public class ChampionController : ControllerBase [HttpPut("Update")] public async Task 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) { @@ -59,7 +63,7 @@ public class ChampionController : ControllerBase return NotFound(); } var updatedChampion = champion.toModel(); - await ChampionsManager.UpdateItem(existingChampion, updatedChampion); + await _dataManager.UpdateItem(existingChampion, updatedChampion); if (updatedChampion.Bio == "string") { updatedChampion.Bio = "Aucune bio"; @@ -71,8 +75,8 @@ public class ChampionController : ControllerBase [HttpDelete("Delete")] public async Task 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 + " } not found !"); return NotFound(); diff --git a/Sources/WebApiLol/Converter/ChampionConverter.cs b/Sources/WebApiLol/Converter/ChampionConverter.cs index 467e89a..3b28218 100644 --- a/Sources/WebApiLol/Converter/ChampionConverter.cs +++ b/Sources/WebApiLol/Converter/ChampionConverter.cs @@ -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); diff --git a/Sources/WebApiLol/Converter/SkinConverter.cs b/Sources/WebApiLol/Converter/SkinConverter.cs index b443519..bc2edb0 100644 --- a/Sources/WebApiLol/Converter/SkinConverter.cs +++ b/Sources/WebApiLol/Converter/SkinConverter.cs @@ -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); diff --git a/Sources/WebApiLol/Program.cs b/Sources/WebApiLol/Program.cs index 62b4262..b4e626f 100644 --- a/Sources/WebApiLol/Program.cs +++ b/Sources/WebApiLol/Program.cs @@ -1,5 +1,8 @@ -var builder = WebApplication.CreateBuilder(args); +using DbDatamanager; +using Model; +var builder = WebApplication.CreateBuilder(args); +builder.Services.AddScoped(); // 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. diff --git a/Sources/WebApiLol/SkinDTO.cs b/Sources/WebApiLol/SkinDTO.cs index 4142b9a..ba2e77a 100644 --- a/Sources/WebApiLol/SkinDTO.cs +++ b/Sources/WebApiLol/SkinDTO.cs @@ -7,15 +7,6 @@ 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; - - } } } diff --git a/Sources/WebApiLol/WebApiLol.csproj b/Sources/WebApiLol/WebApiLol.csproj index 12d51ee..eeef7d8 100644 --- a/Sources/WebApiLol/WebApiLol.csproj +++ b/Sources/WebApiLol/WebApiLol.csproj @@ -11,7 +11,7 @@ - + @@ -28,5 +28,11 @@ + + + + + +