diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj index 72706e0..38ccd8a 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj +++ b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj @@ -20,6 +20,8 @@ + + diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs index 8618a15..1204962 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs @@ -11,7 +11,9 @@ using System.Xml.Linq; namespace API_LoL_Project.Controllers { + /*[Route("api/v{version:apiVersion}/[controller]")]*/ [Route("api/[controller]")] + /*[ApiVersion("1.0")]*/ [ApiController] public class ChampionsController : ControllerBase { @@ -39,33 +41,59 @@ namespace API_LoL_Project.Controllers var totalcount = await dataManager.GetNbItems(); if (request.count + request.index > totalcount) { - _logger.LogWarning("No chamions found with Id"); - return BadRequest("No chamions found with Id "); + _logger.LogWarning("No chamions found"); + return BadRequest("No chamions found"); } + _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request);; var champions = await dataManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending)); IEnumerable res = champions.Select(c => c.toDTO()); if (res.Count() >= 0 || res == null) { - _logger.LogWarning("No chamions found with Id"); - return BadRequest("No chamions found with Id "); + _logger.LogWarning("No chamions found "); + return BadRequest("No chamions found "); } return Ok(res); } catch (Exception e) { + _logger.LogError(""); return BadRequest(e.Message); } - - } + /*// GET api//5 + [HttpGet("{id}")] + public async Task>> GetChampionsById(int name) + { + try + { + + var champion = await dataManager + .GetItemsByName(name, 0, await dataManager.GetNbItems()); + _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name); + IEnumerable res = champion.Select(c => c.toFullDTO()); + + if (res == null) + { + _logger.LogWarning("No chamions found with {name}", name); ; + return NotFound(); + } + return Ok(res); + + } + catch (Exception e) + { + return BadRequest(e.Message); + + } + }*/ // GET api//5 [HttpGet("{name}")] - public async Task> GetChampionsByName(string name) + public async Task>> GetChampionsByName(string name) { try { @@ -73,7 +101,8 @@ namespace API_LoL_Project.Controllers var champion = await dataManager .GetItemsByName(name, 0, await dataManager.GetNbItems()); _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name); - ChampionDTO res = champion.First().toDTO(); + IEnumerable res = champion.Select(c => c.toFullDTO()); + if (res == null) { _logger.LogWarning("No chamions found with {name}", name); ; @@ -187,4 +216,6 @@ namespace API_LoL_Project.Controllers }*/ } + + } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs index f75a599..cbb22fe 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs @@ -2,5 +2,6 @@ { public class PageResponse { + } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs index 7b9a2f2..19f1f02 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs @@ -2,6 +2,8 @@ using Microsoft.AspNetCore.Mvc; using Model; using API_LoL_Project.Mapper; +using System.Xml.Linq; +using System; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -12,7 +14,7 @@ namespace API_LoL_Project.Controllers [ApiController] public class RuneController : ControllerBase { - public IRunesManager runesManager; + /*public IRunesManager runesManager; // you should create a custom logger to be prety private readonly ILogger _logger; @@ -26,7 +28,7 @@ namespace API_LoL_Project.Controllers - /*// GET: api/ + *//*// GET: api/ [HttpGet] public async Task> Get() { @@ -42,7 +44,7 @@ namespace API_LoL_Project.Controllers return BadRequest(e.Message); } - }*/ + }*//* // GET: api/ [HttpGet] @@ -79,21 +81,43 @@ namespace API_LoL_Project.Controllers } - // GET api//5 + *//* // GET api//5 [HttpGet("{id}")] - public string Get(int id) + public string GetRuneById(int id) { try { - var rune = await dataManager - .GetItemsByName(name, 0, await dataManager.GetNbItems()); + var rune = await runesManager.GetItemsByName + .(name, 0, await dataManager.GetNbItems()); RuneDto result = champion.First().toDTO(); return Ok(result); } - catch (Exeption e) + + + }*//* + + // GET api//5 + [HttpGet("{name}")] + public async string GetByRuneName(string name) + { + try + { + var rune = await runesManager + .GetItemsByName(name, 0, await runesManager.GetNbItems()); + _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetByRuneName), name); + RuneDTO res = rune.First().toFullDTO(); + if (res == null) + { + _logger.LogWarning("No rune found with {name}", name); ; + return NotFound(); + } + return Ok(res); + + } + catch (Exception e) { + return BadRequest(e.Message); - new HttpException(400, 'Cannot get rune :' + e.message); } @@ -127,6 +151,6 @@ namespace API_LoL_Project.Controllers [HttpDelete("{id}")] public void Delete(int id) { - } + }*/ } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs index 2d0934b..5dd9088 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs @@ -9,7 +9,7 @@ namespace API_LoL_Project.Controllers public class RunePageController : ControllerBase { // GET: api/ - [HttpGet] + /*[HttpGet] public async Task>> Get([FromQuery] Request.PageRequest request) { try @@ -65,6 +65,6 @@ namespace API_LoL_Project.Controllers [HttpDelete("{id}")] public void Delete(int id) { - } + }*/ } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs deleted file mode 100644 index 950897f..0000000 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs +++ /dev/null @@ -1,70 +0,0 @@ -using Microsoft.AspNetCore.Mvc; - -// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 - -namespace API_LoL_Project.Controllers -{ - [Route("api/[controller]")] - [ApiController] - public class SkillController : ControllerBase - { - // GET: api/ - [HttpGet] - public async Task>> Get([FromQuery] Request.PageRequest request) - { - try - { - var totalcount = await runesManager.GetNbItems(); - if (request.count + request.index > totalcount) - { - _logger.LogWarning("to many rows ask the max is {totalcount}", totalcount); - return BadRequest("to many rows ask the max is " + totalcount); - } - _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); - - - var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending)); - IEnumerable res = runes.Select(c => c.toDTO()); - if (res.Count() >= 0 || res == null) - { - _logger.LogWarning("No runes found with Id"); - return BadRequest("No runes found with Id "); - } - return Ok(res); - } - catch (Exception e) - { - _logger.LogError("About get at {e.message}", DateTime.UtcNow.ToLongTimeString()); - return BadRequest(e.Message); - - } - - - } - - // GET api//5 - [HttpGet("{id}")] - public string Get(int id) - { - return "value"; - } - - // POST api/ - [HttpPost] - public void Post([FromBody] string value) - { - } - - // PUT api//5 - [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) - { - } - - // DELETE api//5 - [HttpDelete("{id}")] - public void Delete(int id) - { - } - } -} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs index db11f8d..0900ac7 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs @@ -1,20 +1,34 @@ -using Microsoft.AspNetCore.Mvc; +using DTO; +using Microsoft.AspNetCore.Mvc; +using Model; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 namespace API_LoL_Project.Controllers { - [Route("api/[controller]")] + /*[Route("api/[controller]")] [ApiController] public class SkinController : ControllerBase { + public ISkinsManager dataManager; + private readonly ILogger _logger; + + *//* public ChampionsController(IChampionsManager dataManager) + { + this.dataManager = dataManager; + }*//* + public SkinController(IDataManager dataManager, ILogger logger) + { + this.dataManager = dataManager.SkinsMgr; + this._logger = logger; + } // GET: api/ [HttpGet] - public async Task>> Get([FromQuery] Request.PageRequest request) + public async Task>> Get([FromQuery] Request.PageRequest request) { try { - var totalcount = await runesManager.GetNbItems(); + var totalcount = await dataManager.GetNbItems(); if (request.count + request.index > totalcount) { _logger.LogWarning("to many rows ask the max is {totalcount}", totalcount); @@ -23,12 +37,12 @@ namespace API_LoL_Project.Controllers _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); - var runes = await runesManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending)); - IEnumerable res = runes.Select(c => c.toDTO()); + var skin = await dataManager.GetItems(request.PageNumber, totalcount, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending)); + IEnumerable res = skin.Select(c => c.toDTO()); if (res.Count() >= 0 || res == null) { - _logger.LogWarning("No runes found with Id"); - return BadRequest("No runes found with Id "); + _logger.LogWarning("No skin founds"); + return BadRequest("No skin founds"); } return Ok(res); } @@ -66,5 +80,5 @@ namespace API_LoL_Project.Controllers public void Delete(int id) { } - } + }*/ } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs index 222e31f..683644f 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs @@ -9,12 +9,38 @@ namespace API_LoL_Project.Mapper public static ChampionDTO toDTO(this Champion item) { - + if (item == null) + { + var message = string.Format("Champion with name = {} nhhoddt found", item.Name); + /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); + */ + } + return new ChampionDTO() { Name = item.Name, Bio = item.Bio }; } + public static ChampionFullDTO toFullDTO(this Champion item) + { + if (item == null) + { + var message = string.Format("Champion with name = {} nhhoddt found", item.Name); + /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); + */ + } + return new ChampionFullDTO() + { + Name = item.Name, + Bio = item.Bio, + Characteristics = item.Characteristics, + skills = item.Skills, + skins = item.Skins, + LargeImage = item.Image + + }; + + } public static Champion toModel(this ChampionDTO dto) { diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinsMappeur.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinsMappeur.cs new file mode 100644 index 0000000..0245763 --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinsMappeur.cs @@ -0,0 +1,6 @@ +namespace API_LoL_Project.Mapper +{ + public class SkinsMappeur + { + } +} diff --git a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs index 5d0e9f6..e95daf9 100644 --- a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs +++ b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs @@ -1,20 +1,22 @@ using Model; +using System.Collections.ObjectModel; namespace DTO { public class ChampionDTO { public string Name { get; set; } - public string Bio { get; set; } + public string Bio { get; set; } + public string Icon { get; set; } /*public string Icon { get; set; } - */ - } + */ + } public class ChampionFullDTO { public string Name { get; set; } public string Bio { get; set; } - public string Characteristics { get; set; } - public byte[] LargeImage { get; set; } + public ReadOnlyDictionary Characteristics { get; set; } + public LargeImage LargeImage { get; set; } public IEnumerable skins { get; set; } public IEnumerable skills { get; set; } diff --git a/EntityFramework_LoL/Sources/DTO/SkillDto.cs b/EntityFramework_LoL/Sources/DTO/SkillDto.cs new file mode 100644 index 0000000..2b7f006 --- /dev/null +++ b/EntityFramework_LoL/Sources/DTO/SkillDto.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class SkillDto + { + public string Name { get; set; } + public string Description { get; set; } + } +} diff --git a/EntityFramework_LoL/Sources/DTO/SkinDto.cs b/EntityFramework_LoL/Sources/DTO/SkinDto.cs new file mode 100644 index 0000000..2c3962b --- /dev/null +++ b/EntityFramework_LoL/Sources/DTO/SkinDto.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class SkinDto + { + public string Name { get; set; } + public string Description { get; set; } + public string Icon { get; set; } + public float Price { get; set; } + + } +} diff --git a/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs b/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs index 1e5be2c..2e17681 100644 --- a/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs +++ b/EntityFramework_LoL/Sources/Test_Api/ChampionControllerTest.cs @@ -1,6 +1,7 @@ using API_LoL_Project.Controllers; using DTO; using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Logging.Abstractions; using Model; using StubLib; using System.Net; @@ -17,14 +18,15 @@ namespace Test_Api { var stubMgr = new StubData(); - championCtrl = new ChampionsController(stubMgr); + championCtrl = new ChampionsController(stubMgr, new NullLogger()); } [TestMethod] public async Task TestGetChampions() { - var getResult = await championCtrl.Get(); + var getResult = await championCtrl.Get(new API_LoL_Project.Controllers.Request.PageRequest()); Console.WriteLine(getResult); + var objectRes = getResult as OkObjectResult; Assert.AreEqual(200, objectRes.StatusCode);