diff --git a/Sources/API_UT/API_UT.csproj b/Sources/API_UT/API_UT.csproj new file mode 100644 index 0000000..74abf5c --- /dev/null +++ b/Sources/API_UT/API_UT.csproj @@ -0,0 +1,10 @@ + + + + Exe + net6.0 + enable + enable + + + diff --git a/Sources/API_UT/Program.cs b/Sources/API_UT/Program.cs new file mode 100644 index 0000000..3751555 --- /dev/null +++ b/Sources/API_UT/Program.cs @@ -0,0 +1,2 @@ +// See https://aka.ms/new-console-template for more information +Console.WriteLine("Hello, World!"); diff --git a/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj b/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj index 6ccc58d..8698ed9 100644 --- a/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj +++ b/Sources/ConsoleDbSQLite/ConsoleDbSQLite.csproj @@ -20,6 +20,7 @@ + diff --git a/Sources/DBDataManager/DBDataManager.csproj b/Sources/DBDataManager/DBDataManager.csproj index 49f43b3..168aadd 100644 --- a/Sources/DBDataManager/DBDataManager.csproj +++ b/Sources/DBDataManager/DBDataManager.csproj @@ -13,6 +13,7 @@ + diff --git a/Sources/DBDataManager/DbDataManager.cs b/Sources/DBDataManager/DbDataManager.cs index 830736c..fb8ae70 100644 --- a/Sources/DBDataManager/DbDataManager.cs +++ b/Sources/DBDataManager/DbDataManager.cs @@ -9,14 +9,14 @@ using System.Threading.Tasks; namespace DBDataManager { - public class DBDataManager //: IDataManager- + public class DbDataManager : IDataManager { - //public IChampionsManager ChampionsManager => new DBChampionManager(); + public IChampionsManager ChampionsMgr => throw new NotImplementedException(); - //public ISkinsManager SkinsManager => throw new NotImplementedException(); + public ISkinsManager SkinsMgr => throw new NotImplementedException(); - //public IRunesManager RunesManager=> throw new NotImplementedException(); + public IRunesManager RunesMgr => throw new NotImplementedException(); - //public IRunePagesManager RunePagesManager=> throw new NotImplementedException(); + public IRunePagesManager RunePagesMgr => throw new NotImplementedException(); } } diff --git a/Sources/Model/Rune.cs b/Sources/Model/Rune.cs index f63ad1c..a868107 100644 --- a/Sources/Model/Rune.cs +++ b/Sources/Model/Rune.cs @@ -48,7 +48,7 @@ namespace Model Description = description; } - public Rune(string name, string description) + public Rune(string name, string description, LargeImage image) { this.name = name; this.description = description; diff --git a/Sources/Model/Skin.cs b/Sources/Model/Skin.cs index 23bd218..697fc68 100644 --- a/Sources/Model/Skin.cs +++ b/Sources/Model/Skin.cs @@ -69,7 +69,7 @@ namespace Model Price = price; } - public Skin(string name, string description, float price) + public Skin(string name, string description, float price, LargeImage image) { this.name = name; this.description = description; diff --git a/Sources/Web_Api/Controllers/ChampionsController.cs b/Sources/Web_Api/Controllers/ChampionsController.cs index 3904e62..ebacbd7 100644 --- a/Sources/Web_Api/Controllers/ChampionsController.cs +++ b/Sources/Web_Api/Controllers/ChampionsController.cs @@ -15,7 +15,7 @@ namespace Web_Api.Controllers public class ChampionsController : ControllerBase { - private StubData.ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData()); + private ChampionsManager ChampionsManager { get; set; } = new StubData.ChampionsManager(new StubData()); private readonly LolContext _context; @@ -47,8 +47,7 @@ namespace Web_Api.Controllers var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null); if (championSelected.Count() == 0) { - Console.WriteLine("Aucun champion ne correspond au nom { " + name + " } !"); - throw new Exception("Aucun champion ne correspond au nom { " + name + " } !"); + return NotFound("Aucun champion ne correspond au nom { " + name + " } !"); } Console.WriteLine("Le champion { " + name + " } existe"); return Ok(championSelected.Select(champion => champion?.toDTO())); @@ -63,8 +62,7 @@ namespace Web_Api.Controllers { champion.Bio = "Aucune bio"; } - Console.WriteLine("Le champion { " + champion.Name + " } avec pour bio { " + champion.Bio + " } a bien été ajouté"); - return Ok(); + return Ok("Le champion { " + champion.Name + " } avec pour bio { " + champion.Bio + " } a bien été ajouté"); } [HttpPut("UPDATE")] @@ -74,8 +72,7 @@ namespace Web_Api.Controllers var existingChampion = championSelected.FirstOrDefault(); if (existingChampion == null) { - Console.WriteLine("Le champion { " + name + " } n'existe pas !"); - return NotFound(); + return NotFound("Le champion { " + name + " } n'existe pas !"); } var updatedChampion = champion.toModel(); await ChampionsManager.UpdateItem(existingChampion, updatedChampion); @@ -83,8 +80,7 @@ namespace Web_Api.Controllers { updatedChampion.Bio = "Aucune bio"; } - Console.WriteLine("Le champion { " + name + " } a été modifié en { " + updatedChampion.Name + " } avec pour bio { " + updatedChampion.Bio + " }"); - return Ok(); + return Ok("Le champion { " + name + " } a été modifié en { " + updatedChampion.Name + " } avec pour bio { " + updatedChampion.Bio + " }"); } [HttpDelete("DELETE")] @@ -93,91 +89,9 @@ namespace Web_Api.Controllers var championSelected = await ChampionsManager.GetItemsByName(name, 0, await ChampionsManager.GetNbItemsByName(name), null); if(!await ChampionsManager.DeleteItem(championSelected.FirstOrDefault())) { - Console.WriteLine("champion { " + name + " } non trouvé !"); - return NotFound(); + return NotFound("champion { " + name + " } non trouvé !"); } - Console.WriteLine("champion { " + name + " } supprimé"); - return Ok(); + return Ok("champion { " + name + " } supprimé"); } - - /*[HttpGet(Name = "GetChampionsById")] - public async Task GetById() - { - - }*/ - /*// GET: ChampionsController - public ActionResult Index() - { - return View(); - } - - // GET: ChampionsController/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: ChampionsController/Create - public ActionResult Create() - { - return View(); - } - - // POST: ChampionsController/Create - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } - - // GET: ChampionsController/Edit/5 - public ActionResult Edit(int id) - { - return View(); - } - - // POST: ChampionsController/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } - - // GET: ChampionsController/Delete/5 - public ActionResult Delete(int id) - { - return View(); - } - - // POST: ChampionsController/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - }*/ } } diff --git a/Sources/Web_Api/Controllers/RunesController.cs b/Sources/Web_Api/Controllers/RunesController.cs index 2745d48..0225bfa 100644 --- a/Sources/Web_Api/Controllers/RunesController.cs +++ b/Sources/Web_Api/Controllers/RunesController.cs @@ -10,7 +10,7 @@ namespace Web_Api.Controllers [Route("api/[controller]")] public class RunesController : Controller { - private StubData.RunesManager RunesManager { get; set; } = new StubData.RunesManager(new StubData()); + private RunesManager RunesManager { get; set; } = new StubData.RunesManager(new StubData()); private readonly ILogger _logger; @@ -32,8 +32,7 @@ namespace Web_Api.Controllers var runesSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null); if (runesSelected.Count() == 0) { - Console.WriteLine("Aucune rune ne correspond au nom { " + name + " } !"); - throw new Exception("Aucune rune ne correspond au nom { " + name + " } !"); + return NotFound("Aucune rune ne correspond au nom { " + name + " } !"); } Console.WriteLine("La rune { " + name + " } existe"); return Ok(runesSelected.Select(runes => runes?.toDTO())); @@ -59,8 +58,7 @@ namespace Web_Api.Controllers var existingRune = runeSelected.FirstOrDefault(); if (existingRune == null) { - Console.WriteLine("La rune { " + name + " } n'existe pas !"); - return NotFound(); + return NotFound("La rune { " + name + " } n'existe pas !"); } var updatedRune = rune.toModel(); await RunesManager.UpdateItem(existingRune, updatedRune); @@ -68,8 +66,7 @@ namespace Web_Api.Controllers { rune.Description = "Aucune bio"; } - Console.WriteLine("La rune { " + name + " } a été modifiée en { " + updatedRune.Name + " } avec pour description { " + rune.Description + " }"); - return Ok(); + return Ok("La rune { " + name + " } a été modifiée en { " + updatedRune.Name + " } avec pour description { " + rune.Description + " }"); } [HttpDelete("DELETE")] @@ -78,85 +75,9 @@ namespace Web_Api.Controllers var runeSelected = await RunesManager.GetItemsByName(name, 0, await RunesManager.GetNbItemsByName(name), null); if(!await RunesManager.DeleteItem(runeSelected.FirstOrDefault())) { - Console.WriteLine("rune { " + name + " } non trouvée !"); - return NotFound(); + return NotFound("rune { " + name + " } non trouvée !"); } - Console.WriteLine("rune { " + name + " } supprimée"); - return Ok(); + return Ok("rune { " + name + " } supprimée"); } - /*// GET: RuneController - public ActionResult Index() - { - return View(); - } - - // GET: RuneController/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: RuneController/Create - public ActionResult Create() - { - return View(); - } - - // POST: RuneController/Create - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } - - // GET: RuneController/Edit/5 - public ActionResult Edit(int id) - { - return View(); - } - - // POST: RuneController/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } - - // GET: RuneController/Delete/5 - public ActionResult Delete(int id) - { - return View(); - } - - // POST: RuneController/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - }*/ } } diff --git a/Sources/Web_Api/Controllers/SkinsController.cs b/Sources/Web_Api/Controllers/SkinsController.cs index 63e9565..5d4e48f 100644 --- a/Sources/Web_Api/Controllers/SkinsController.cs +++ b/Sources/Web_Api/Controllers/SkinsController.cs @@ -9,7 +9,7 @@ namespace Web_Api.Controllers [Route("api/[controller]")] public class SkinsController : Controller { - private StubData.SkinsManager SkinsManager { get; set; } = new StubData.SkinsManager(new StubData()); + private SkinsManager SkinsManager { get; set; } = new StubData.SkinsManager(new StubData()); private readonly ILogger _logger; @@ -58,8 +58,7 @@ namespace Web_Api.Controllers var existingSkin = skinSelected.FirstOrDefault(); if(existingSkin == null) { - Console.WriteLine("Le skin { " + name + " } n'existe pas !"); - return NotFound(); + return NotFound("Le skin { " + name + " } n'existe pas !"); } var updatedSkin = skin.toModel(); @@ -68,8 +67,7 @@ namespace Web_Api.Controllers { skin.Description = "Aucune bio"; } - Console.WriteLine("Le skin { " + name + " } a été modifié en " + " { " + updatedSkin.Name + " } avec pour description { " + updatedSkin.Description + " }<"); - return Ok(); + return Ok("Le skin { " + name + " } a été modifié en " + " { " + updatedSkin.Name + " } avec pour description { " + updatedSkin.Description + " }<"); } [HttpDelete("DELETE")] @@ -78,85 +76,10 @@ namespace Web_Api.Controllers var skinSelected = await SkinsManager.GetItemsByName(name, 0, await SkinsManager.GetNbItemsByName(name), null); if (!await SkinsManager.DeleteItem(skinSelected.FirstOrDefault())) { - Console.WriteLine("skin { " + name + " } non trouvé !"); - return NotFound(); + return NotFound("skin { " + name + " } non trouvé !"); } Console.WriteLine("skin { " + name + " } supprimé"); return Ok(); } - /*// GET: SkinsController - public ActionResult Index() - { - return View(); - } - - // GET: SkinsController/Details/5 - public ActionResult Details(int id) - { - return View(); - } - - // GET: SkinsController/Create - public ActionResult Create() - { - return View(); - } - - // POST: SkinsController/Create - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Create(IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } - - // GET: SkinsController/Edit/5 - public ActionResult Edit(int id) - { - return View(); - } - - // POST: SkinsController/Edit/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Edit(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - } - - // GET: SkinsController/Delete/5 - public ActionResult Delete(int id) - { - return View(); - } - - // POST: SkinsController/Delete/5 - [HttpPost] - [ValidateAntiForgeryToken] - public ActionResult Delete(int id, IFormCollection collection) - { - try - { - return RedirectToAction(nameof(Index)); - } - catch - { - return View(); - } - }*/ } } diff --git a/Sources/Web_Api/Program.cs b/Sources/Web_Api/Program.cs index e348fc8..dda2b35 100644 --- a/Sources/Web_Api/Program.cs +++ b/Sources/Web_Api/Program.cs @@ -2,12 +2,22 @@ using EntityFrameworkLib; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi.Models; +using Model; using Web_Api.Controllers; var builder = WebApplication.CreateBuilder(args); -builder.Services.AddDbContext(options => - options.UseSqlite($"DataSource=projet.Champions.db")); +builder.Services.AddDbContext(); + +var app = builder.Build(); + +using (var scope = app.Services.CreateScope()) +{ + var context = scope.ServiceProvider.GetService(); + context.Database.EnsureCreated(); +} + +builder.Services.AddHttpClient(); // Add services to the container. diff --git a/Sources/Web_Api/RuneDTO.cs b/Sources/Web_Api/RuneDTO.cs index 6ff89e1..dd9e04e 100644 --- a/Sources/Web_Api/RuneDTO.cs +++ b/Sources/Web_Api/RuneDTO.cs @@ -10,9 +10,11 @@ namespace Web_Api public string Description { get; set; } + public LargeImage Image { get; set; } + public Rune toModel() { - return new Rune(Name, Description); + return new Rune(Name, Description, Image); } } } diff --git a/Sources/Web_Api/SkinDTO.cs b/Sources/Web_Api/SkinDTO.cs index a5290ea..57b5cd6 100644 --- a/Sources/Web_Api/SkinDTO.cs +++ b/Sources/Web_Api/SkinDTO.cs @@ -12,9 +12,11 @@ namespace Web_Api public float Price { get; set; } + public LargeImage Image { get; set; } + public Skin toModel() { - return new Skin(Name, Description, Price); + return new Skin(Name, Description, Price, Image); } } } diff --git a/Sources/Web_Api/Web_Api.csproj b/Sources/Web_Api/Web_Api.csproj index b227040..daec55c 100644 --- a/Sources/Web_Api/Web_Api.csproj +++ b/Sources/Web_Api/Web_Api.csproj @@ -12,6 +12,7 @@ +