diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs deleted file mode 100644 index 271d180..0000000 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs +++ /dev/null @@ -1,71 +0,0 @@ -using DTO; -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 RunePageController : 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/SkillController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs deleted file mode 100644 index 042bc7e..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 deleted file mode 100644 index 9f41870..0000000 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs +++ /dev/null @@ -1,80 +0,0 @@ -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]")] - [ApiController] - public class SkinController : ControllerBase - { - /* public ISkinsManager dataManager; - private readonly ILogger _logger; - public SkinController(IDataManager dataManager, ILogger logger) - { - this.dataManager = dataManager.SkinsMgr; - this._logger = logger; - } - - // GET: api/ - [HttpGet] - public async Task>> Get([FromQuery] Request.PageRequest request) - { - try - { - var totalcount = await dataManager.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 dataManager.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/version1/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/ChampionsController.cs index 13fd762..86e7c1d 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/ChampionsController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/ChampionsController.cs @@ -327,7 +327,9 @@ namespace API_LoL_Project.Controllers.version1 } // degradation du modèle cleitn ell est dédié au cliens - [HttpGet("/count")] + // GET: api/champions/Count + + [HttpGet("/count", Name = "GetChampionCount")] public async Task> NbChampions() { var nbChampions = await dataManager.GetNbItems(); diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/RuneController.cs similarity index 95% rename from EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs rename to EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/RuneController.cs index 2bef43b..744ea0c 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/RuneController.cs @@ -1,189 +1,189 @@ -using DTO; -using Microsoft.AspNetCore.Mvc; -using Model; -using API_LoL_Project.Mapper; -using API_LoL_Project.Controllers.Response; -using API_LoL_Project.Middleware; - - -// 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 RuneController : ControllerBase - { - public IRunesManager dataManager; - // you should create a custom logger to be prety - private readonly ILogger _logger; - - - public RuneController(IDataManager dataManager, ILogger logger) - { - this.dataManager = dataManager.RunesMgr; - - this._logger = logger; - } - - - - /*// GET: api/ - [HttpGet] - public async Task>> GetAllRunes([FromQuery] Request.PageRequest request) - { - try - { - var totalcount = await dataManager.GetNbItems(); - if (request.count * request.index >= totalcount) - { - _logger.LogError("To many object is asked the max is {totalcount} but the request is supérior of ", totalcount); - return BadRequest("To many object is asked the max is : " + totalcount); - } - - _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(GetAllRunes), request); ; - var runes = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending)); - IEnumerable res = runes.Select(c => c.toDTO()); - if (res.Count() <= 0 || res == null) - { - _logger.LogError("No runes found the total count is {totalcount} ", totalcount); - return BadRequest("No runes found : totalcount is : " + totalcount); - } - - var respList = res.Select(r => new LolResponce - ( - r, - new List - { - EndPointLink.To($"/api/[controller]/{r.Name}", "self"), - EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"), - EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"), - EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"), - EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self","POST"), - EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"), - } - )); - - var pageResponse = new PageResponse(respList, request.index, request.count, totalcount); - - return Ok(pageResponse); - } - catch (Exception e) - { - _logger.LogError("Somthing goes wrong caching the Rune controller : " + e.Message); - return BadRequest(e.Message); - - } - } - */ - - - // 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); - - } - - - } - */ - /* - [HttpGet("{name}")] - public async Task>> GetRuneByName(string name) - { - try - { - - var rune = await dataManager - .GetItemsByName(name, 0, await dataManager.GetNbItems()); - _logger.LogInformation("Executing {Action} with name : {runeName}", nameof(GetRuneByName), name); - RuneDTO res = rune.First().toDTO(); - - if (res == null) - { - _logger.LogWarning("No runes found with {name}", name); ; - return NotFound(); - } - var links = new List - { - EndPointLink.To($"/api/[controller]/{res.Name}", "self"), - EndPointLink.To($"/api/[controller]/{res.Name}/", "self"), - EndPointLink.To($"/api/[controller]/{res.Name}/", "self") - }; - - var response = new LolResponce(res, links); - return Ok(response); - - } - catch (Exception e) - { - - _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message); - return BadRequest(e.Message); - - } - }*/ - - /* // GET api//5 - [HttpGet("{id}")] - public string Get(int id) - { - try - { - var rune = await dataManager - .GetItemsByName(name, 0, await dataManager.GetNbItems()); - RuneDto result = champion.First().toDTO(); - return Ok(result); - } - catch (Exeption e) - { - - new HttpException(400, 'Cannot get rune :' + e.message); - } - - - }*/ - - // POST api/ - - - // PUT api//5 - [HttpPut("{id}")] - public void Put(int id, [FromBody] string value) - { - - } - - // DELETE api//5 - [HttpDelete("{id}")] - public void Delete(int id) - { - } - } -} +using DTO; +using Microsoft.AspNetCore.Mvc; +using Model; +using API_LoL_Project.Controllers.Response; +using API_LoL_Project.Middleware; + + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace API_LoL_Project.Controllers.version1 +{ + + [Route("api/v{version:apiVersion}/[controller]")] + [ApiVersion("1.0")] + [ApiController] + public class RuneController : ControllerBase + { + public IRunesManager dataManager; + // you should create a custom logger to be prety + private readonly ILogger _logger; + + + public RuneController(IDataManager dataManager, ILogger logger) + { + this.dataManager = dataManager.RunesMgr; + + _logger = logger; + } + + + + /*// GET: api/ + [HttpGet] + public async Task>> GetAllRunes([FromQuery] Request.PageRequest request) + { + try + { + var totalcount = await dataManager.GetNbItems(); + if (request.count * request.index >= totalcount) + { + _logger.LogError("To many object is asked the max is {totalcount} but the request is supérior of ", totalcount); + return BadRequest("To many object is asked the max is : " + totalcount); + } + + _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(GetAllRunes), request); ; + var runes = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending)); + IEnumerable res = runes.Select(c => c.toDTO()); + if (res.Count() <= 0 || res == null) + { + _logger.LogError("No runes found the total count is {totalcount} ", totalcount); + return BadRequest("No runes found : totalcount is : " + totalcount); + } + + var respList = res.Select(r => new LolResponce + ( + r, + new List + { + EndPointLink.To($"/api/[controller]/{r.Name}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self","POST"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"), + } + )); + + var pageResponse = new PageResponse(respList, request.index, request.count, totalcount); + + return Ok(pageResponse); + } + catch (Exception e) + { + _logger.LogError("Somthing goes wrong caching the Rune controller : " + e.Message); + return BadRequest(e.Message); + + } + } + */ + + + // 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); + + } + + + } + */ + /* + [HttpGet("{name}")] + public async Task>> GetRuneByName(string name) + { + try + { + + var rune = await dataManager + .GetItemsByName(name, 0, await dataManager.GetNbItems()); + _logger.LogInformation("Executing {Action} with name : {runeName}", nameof(GetRuneByName), name); + RuneDTO res = rune.First().toDTO(); + + if (res == null) + { + _logger.LogWarning("No runes found with {name}", name); ; + return NotFound(); + } + var links = new List + { + EndPointLink.To($"/api/[controller]/{res.Name}", "self"), + EndPointLink.To($"/api/[controller]/{res.Name}/", "self"), + EndPointLink.To($"/api/[controller]/{res.Name}/", "self") + }; + + var response = new LolResponce(res, links); + return Ok(response); + + } + catch (Exception e) + { + + _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message); + return BadRequest(e.Message); + + } + }*/ + + /* // GET api//5 + [HttpGet("{id}")] + public string Get(int id) + { + try + { + var rune = await dataManager + .GetItemsByName(name, 0, await dataManager.GetNbItems()); + RuneDto result = champion.First().toDTO(); + return Ok(result); + } + catch (Exeption e) + { + + new HttpException(400, 'Cannot get rune :' + e.message); + } + + + }*/ + + // POST api/ + + + // 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/version1/RunePageController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/RunePageController.cs new file mode 100644 index 0000000..da564bc --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version1/RunePageController.cs @@ -0,0 +1,219 @@ +using API_LoL_Project.Controllers.Response; +using API_LoL_Project.Middleware; +using DTO; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Hosting; +using Model; +using ApiMappeur; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace API_LoL_Project.Controllers.version1 +{ + [Route("api/v{version:apiVersion}/[controller]")] + [ApiVersion("1.0")] + [ApiController] + public class RunePageController : ControllerBase + { + private IRunePagesManager dataManager; + private readonly ILogger _logger; + + public RunePageController(IDataManager dataManager, ILogger logger) + { + this.dataManager = dataManager.RunePagesMgr; + _logger = logger; + } + // GET: api/v1/ + [HttpGet] + public async Task>> Get([FromQuery] Request.PageRequest request) + { + try + { + var totalcount = await dataManager.GetNbItems(); + if (request.count * request.index >= totalcount) + { + _logger.LogError("To many object is asked the max is {totalcount} but the request is superior of ", totalcount); + return BadRequest("To many object is asked the max is : " + totalcount); + } + _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); + + var runesP = await dataManager.GetItems(request.index, request.count == 0 ? totalcount : request.count, request.orderingPropertyName, request.descending == null ? false : (bool)request.descending); + IEnumerable res = runesP.Select(c => c.ToDto()); + if (res.Count() <= 0 || res == null) + { + _logger.LogError("No RunePage found the total count is {totalcount} ", totalcount); + return BadRequest("No RunePage found : totalcount is : " + totalcount); + } + + var respList = res.Select(r => new LolResponse + ( + r, + new List + { + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetRunePageByName)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"), + } + )); + + var pageResponse = new PageResponse(respList, request.index, request.count, totalcount); + + return Ok(pageResponse); + } + catch (Exception e) + { + _logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message); + return BadRequest(e.Message); + + } + } + + [HttpGet("{name}")] + public async Task>>> GetRunePageByName(string name) + { + if (name == null || name == "") + { + var message = string.Format("Can not get Rune PAge without the name (is empty)"); + _logger.LogWarning(message); ; + return BadRequest(message); + } + _logger.LogInformation("Executing {Action} with name : {runePageName}", nameof(GetRunePageByName), name); + try + { + var totalcount = await dataManager.GetNbItemsByName(name); + if (totalcount <= 0) + { + _logger.LogError("No chamions found with this name {name} in the dataContext", name); ; + return NotFound("No chamions found with this name: " + name + "in the dataContext"); + } + var champion = await dataManager.GetItemsByName(name, 0, totalcount); + _logger.LogInformation($"========================= {champion} ================================================"); ; + + if (champion.Count() <= 0 || champion == null) + { + _logger.LogError($"No chamions found with {name} executing {nameof(GetRunePageByName)}"); ; + return NotFound("No chamions found with" + name); + } + IEnumerable res = champion.Select(c => c.ToDto()); + /*ChampionFullDTO res = champion.First().toFullDTO();//.First*/ + var respList = res.Select(r => new LolResponse + ( + r, + new List + { + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetRunePageByName)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"), + } + )); + + return Ok(respList); + + } + catch (Exception e) + { + + _logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message); + return BadRequest("Somthing goes wrong caching the RunePage controller : " + e.Message); + + } + } + + + [HttpPost] + public async Task Post([FromBody] RunePageDTO runePage) + { + _logger.LogInformation("method {Action} - RUNEPAGE call with {item}", nameof(Post), runePage); + try + { + if (await dataManager.GetNbItemsByName(runePage.Name) == 0) + { + return CreatedAtAction(nameof(Get), + (await dataManager.AddItem(runePage.ToModel())).ToDto()); + } + _logger.LogWarning($"Name : {runePage.Name} is already exist"); + return BadRequest($"Name : {runePage.Name} is already exist"); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } + + [HttpPut("{name}")] + public async Task Put(string name, [FromBody] RunePageDTO value) + { + try + { + _logger.LogInformation("Executing {Action} with name : {championName}", nameof(Put), name); + var champion = await dataManager + .GetItemsByName(name, 0, await dataManager.GetNbItems()); + if (champion == null) + { + _logger.LogError("No chamions found with {name} in the dataBase", name); ; + return NotFound(); + } + + var savedUpdatedRunePage = await dataManager.UpdateItem(champion.First(), value.ToModel()); + if (savedUpdatedRunePage == null) + { + + _logger.LogWarning("The updated RunePage not returned {name}", name); ; + return BadRequest(); + + } + return Ok(savedUpdatedRunePage); + } + catch (Exception e) + { + _logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message); + return BadRequest(e.Message); + } + } + + + [HttpDelete("{name}")] + public async Task Delete(string name) + { + _logger.LogInformation("method {Action} - RUNEPAGE call with {name}", nameof(Delete), name); + try + { + var dtos = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()); + if (dtos == null) + { + _logger.LogWarning("{name} was not found", name); + return NotFound($"{name} was not found"); + } + await dataManager.DeleteItem(dtos.First()); + return NoContent(); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } + // GET: api//count + [HttpGet("/countRunePage", Name = "GetRunePageCount")] + public async Task> NbRunePage() + { + _logger.LogInformation("method {Action} - RUNEPAGE call", nameof(NbRunePage)); + try + { + var nbRunePage = await dataManager.GetNbItems(); + return Ok(nbRunePage); + + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + + } + + } + + + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/ChampionsController.cs index 0092dd4..8a5ced6 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/ChampionsController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/ChampionsController.cs @@ -412,13 +412,27 @@ namespace API_LoL_Project.Controllers.version2 return Ok(res); } - // degradation du modèle cleitn ell est dédié au cliens - [HttpGet("/count")] + // degradation du modèle cleitn ell est dédié au client + // GET: api/champions/Count + [HttpGet("/count", Name = "GetChampionCount")] public async Task> NbChampions() { - var nbChampions = await dataManager.GetNbItems(); - return Ok(nbChampions); + _logger.LogInformation("method {Action} - RUNEPAGE call", nameof(NbChampions)); + try + { + var nbChampions = await dataManager.GetNbItems(); + return Ok(nbChampions); + + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + + } + } + [HttpGet("count/class/{championClass}")] public async Task> GetChampionCountByClass(ChampionClass championClass) { diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/RuneController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/RuneController.cs new file mode 100644 index 0000000..3b01397 --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/RuneController.cs @@ -0,0 +1,189 @@ +using DTO; +using Microsoft.AspNetCore.Mvc; +using Model; +using API_LoL_Project.Controllers.Response; +using API_LoL_Project.Middleware; + + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace API_LoL_Project.Controllers.version2 +{ + + [Route("api/v{version:apiVersion}/[controller]")] + [ApiVersion("2.0")] + [ApiController] + public class RuneController : ControllerBase + { + public IRunesManager dataManager; + // you should create a custom logger to be prety + private readonly ILogger _logger; + + + public RuneController(IDataManager dataManager, ILogger logger) + { + this.dataManager = dataManager.RunesMgr; + + _logger = logger; + } + + + + /*// GET: api/ + [HttpGet] + public async Task>> GetAllRunes([FromQuery] Request.PageRequest request) + { + try + { + var totalcount = await dataManager.GetNbItems(); + if (request.count * request.index >= totalcount) + { + _logger.LogError("To many object is asked the max is {totalcount} but the request is supérior of ", totalcount); + return BadRequest("To many object is asked the max is : " + totalcount); + } + + _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(GetAllRunes), request); ; + var runes = await dataManager.GetItems(request.index, request.count, request.orderingPropertyName, (request.descending == null ? false : (bool)request.descending)); + IEnumerable res = runes.Select(c => c.toDTO()); + if (res.Count() <= 0 || res == null) + { + _logger.LogError("No runes found the total count is {totalcount} ", totalcount); + return BadRequest("No runes found : totalcount is : " + totalcount); + } + + var respList = res.Select(r => new LolResponce + ( + r, + new List + { + EndPointLink.To($"/api/[controller]/{r.Name}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetAllRunes)}", "self","POST"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"), + } + )); + + var pageResponse = new PageResponse(respList, request.index, request.count, totalcount); + + return Ok(pageResponse); + } + catch (Exception e) + { + _logger.LogError("Somthing goes wrong caching the Rune controller : " + e.Message); + return BadRequest(e.Message); + + } + } + */ + + + // 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); + + } + + + } + */ + /* + [HttpGet("{name}")] + public async Task>> GetRuneByName(string name) + { + try + { + + var rune = await dataManager + .GetItemsByName(name, 0, await dataManager.GetNbItems()); + _logger.LogInformation("Executing {Action} with name : {runeName}", nameof(GetRuneByName), name); + RuneDTO res = rune.First().toDTO(); + + if (res == null) + { + _logger.LogWarning("No runes found with {name}", name); ; + return NotFound(); + } + var links = new List + { + EndPointLink.To($"/api/[controller]/{res.Name}", "self"), + EndPointLink.To($"/api/[controller]/{res.Name}/", "self"), + EndPointLink.To($"/api/[controller]/{res.Name}/", "self") + }; + + var response = new LolResponce(res, links); + return Ok(response); + + } + catch (Exception e) + { + + _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message); + return BadRequest(e.Message); + + } + }*/ + + /* // GET api//5 + [HttpGet("{id}")] + public string Get(int id) + { + try + { + var rune = await dataManager + .GetItemsByName(name, 0, await dataManager.GetNbItems()); + RuneDto result = champion.First().toDTO(); + return Ok(result); + } + catch (Exeption e) + { + + new HttpException(400, 'Cannot get rune :' + e.message); + } + + + }*/ + + // POST api/ + + + // 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/version2/RunePageController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/RunePageController.cs new file mode 100644 index 0000000..999438b --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/RunePageController.cs @@ -0,0 +1,218 @@ +using API_LoL_Project.Controllers.Response; +using API_LoL_Project.Middleware; +using DTO; +using Microsoft.AspNetCore.Mvc; +using Microsoft.Extensions.Hosting; +using Model; +using ApiMappeur; + +// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 + +namespace API_LoL_Project.Controllers.version2 +{ + [Route("api/v{version:apiVersion}/[controller]")] + [ApiVersion("2.0")] + [ApiController] + public class RunePageController : ControllerBase + { + private IRunePagesManager dataManager; + private readonly ILogger _logger; + + public RunePageController(IDataManager dataManager, ILogger logger) + { + this.dataManager = dataManager.RunePagesMgr; + _logger = logger; + } + // GET: api/ + [HttpGet] + public async Task>> Get([FromQuery] Request.PageRequest request) + { + try + { + var totalcount = await dataManager.GetNbItems(); + if (request.count * request.index >= totalcount) + { + _logger.LogError("To many object is asked the max is {totalcount} but the request is superior of ", totalcount); + return BadRequest("To many object is asked the max is : " + totalcount); + } + _logger.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); + + var runesP = await dataManager.GetItems(request.index, request.count == 0 ? totalcount : request.count, request.orderingPropertyName, request.descending == null ? false : (bool)request.descending); + IEnumerable res = runesP.Select(c => c.ToDto()); + if (res.Count() <= 0 || res == null) + { + _logger.LogError("No RunePage found the total count is {totalcount} ", totalcount); + return BadRequest("No RunePage found : totalcount is : " + totalcount); + } + + var respList = res.Select(r => new LolResponse + ( + r, + new List + { + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetRunePageByName)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"), + } + )); + + var pageResponse = new PageResponse(respList, request.index, request.count, totalcount); + + return Ok(pageResponse); + } + catch (Exception e) + { + _logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message); + return BadRequest(e.Message); + + } + } + // GET: api/ + [HttpGet("{name}")] + public async Task>>> GetRunePageByName(string name) + { + if (name == null || name == "") + { + var message = string.Format("Can not get Rune PAge without the name (is empty)"); + _logger.LogWarning(message); ; + return BadRequest(message); + } + _logger.LogInformation("Executing {Action} with name : {runePageName}", nameof(GetRunePageByName), name); + try + { + var totalcount = await dataManager.GetNbItemsByName(name); + if (totalcount <= 0) + { + _logger.LogError("No RunePage found with this name {name} in the dataContext", name); ; + return NotFound("No RunePage found with this name: " + name + "in the dataContext"); + } + var runeP = await dataManager.GetItemsByName(name, 0, totalcount); + _logger.LogInformation($"========================= {runeP} ================================================"); ; + + if (runeP.Count() <= 0 || runeP == null) + { + _logger.LogError($"No RunePage found with {name} executing {nameof(GetRunePageByName)}"); ; + return NotFound("No RunePage found with" + name); + } + IEnumerable res = runeP.Select(c => c.ToDto()); + var respList = res.Select(r => new LolResponse + ( + r, + new List + { + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetRunePageByName)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Post)}", "self","POST"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Put)}", "self","PUT"), + } + )); + + return Ok(respList); + + } + catch (Exception e) + { + + _logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message); + return BadRequest("Somthing goes wrong caching the RunePage controller : " + e.Message); + + } + } + + + [HttpPost] + public async Task Post([FromBody] RunePageDTO runePage) + { + _logger.LogInformation("method {Action} - RUNEPAGE call with {item}", nameof(Post), runePage); + try + { + if (await dataManager.GetNbItemsByName(runePage.Name) == 0) + { + return CreatedAtAction(nameof(Get), + (await dataManager.AddItem(runePage.ToModel())).ToDto()); + } + _logger.LogWarning($"Name : {runePage.Name} is already exist"); + return BadRequest($"Name : {runePage.Name} is already exist"); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } + + [HttpPut("{name}")] + public async Task Put(string name, [FromBody] RunePageDTO value) + { + try + { + _logger.LogInformation("Executing {Action} with name : {RunePageName}", nameof(Put), name); + var runeP = await dataManager + .GetItemsByName(name, 0, await dataManager.GetNbItems()); + if (runeP == null) + { + _logger.LogError("No RunePage found with {name} in the dataBase", name); ; + return NotFound(); + } + + var savedUpdatedRunePage = await dataManager.UpdateItem(runeP.First(), value.ToModel()); + if (savedUpdatedRunePage == null) + { + + _logger.LogWarning("The updated RunePage not returned {name}", name); ; + return BadRequest(); + + } + return Ok(savedUpdatedRunePage); + } + catch (Exception e) + { + _logger.LogError("Somthing goes wrong caching the RunePage controller : " + e.Message); + return BadRequest(e.Message); + } + } + + + [HttpDelete("{name}")] + public async Task Delete(string name) + { + _logger.LogInformation("method {Action} - RUNEPAGE call with {name}", nameof(Delete), name); + try + { + var dtos = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()); + if (dtos == null) + { + _logger.LogWarning("{name} was not found", name); + return NotFound($"{name} was not found"); + } + await dataManager.DeleteItem(dtos.First()); + return NoContent(); + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + } + } + // GET: api//count + [HttpGet("/countRunePage", Name = "GetRunePageCount") ] + public async Task> NbRunePage() + { + _logger.LogInformation("method {Action} - RUNEPAGE call", nameof(NbRunePage)); + try + { + var nbRunePage = await dataManager.GetNbItems(); + return Ok(nbRunePage); + + } + catch (Exception error) + { + _logger.LogError(error.Message); + return BadRequest(error.Message); + + } + + } + + + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/SkillController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/SkillController.cs new file mode 100644 index 0000000..d5bf11d --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/SkillController.cs @@ -0,0 +1,71 @@ +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.version2 +{ + [Route("api/v{version:apiVersion}/[controller]")] + [ApiVersion("2.0")] + [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/version2/SkinController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/SkinController.cs new file mode 100644 index 0000000..b4084ae --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/version2/SkinController.cs @@ -0,0 +1,81 @@ +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.version2 +{ + [Route("api/v{version:apiVersion}/[controller]")] + [ApiVersion("2.0")] + [ApiController] + public class SkinController : ControllerBase + { + /* public ISkinsManager dataManager; + private readonly ILogger _logger; + public SkinController(IDataManager dataManager, ILogger logger) + { + this.dataManager = dataManager.SkinsMgr; + this._logger = logger; + } + + // GET: api/ + [HttpGet] + public async Task>> Get([FromQuery] Request.PageRequest request) + { + try + { + var totalcount = await dataManager.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 dataManager.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/Entities.LolDatabase.db b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db index 8d32501..81dae89 100644 Binary files a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db and b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db differ diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm index 15ec3d7..0d14dc2 100644 Binary files a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm and b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm differ diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal index bca48de..b708523 100644 Binary files a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal and b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal differ diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/LolSwaggerOptions.cs b/EntityFramework_LoL/Sources/API_LoL_Project/LolSwaggerOptions.cs index 14c6270..c33a20e 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/LolSwaggerOptions.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/LolSwaggerOptions.cs @@ -50,7 +50,7 @@ namespace API_LoL_Project { var info = new OpenApiInfo() { - Title = ".NET Core (.NET 6) Web API", + Title = ".NET Core (.NET 6) Web API For Lol", Version = desc.ApiVersion.ToString() }; diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs deleted file mode 100644 index c510a87..0000000 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs +++ /dev/null @@ -1,39 +0,0 @@ -using DTO; -using Entities; -using Model; - -namespace API_LoL_Project.Mapper -{ - public static class ChampionMapper { - - public static ChampionEntity ToEntity(this Champion item) - { - return new() - { - Name = item.Name, - Bio = item.Bio, - Icon = item.Icon, - Class = item.Class, - Image = new() { Base64 = item.Image.Base64 }, - }; - } - - public static Champion ToModel(this ChampionDTO dto) - { - if (dto == null) - { - var message = string.Format("Champion with name = {} nhhoddt found", dto.Name); - /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); - */} - return new(dto.Name); - } - - public static Champion ToModel(this ChampionEntity entity) - { - return new(entity.Name, entity.Class, entity.Icon, entity.Image.Base64, entity.Bio); - } - - - - } -} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs deleted file mode 100644 index 8c6d64a..0000000 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace API_LoL_Project.Mapper -{ - using DTO; - using Model; - - namespace API_LoL_Project.Mapper - { - public static class RuneMapper - { - public static RuneDTO ToDTO(this Rune item) - { - - return new RuneDTO() - { - Name = item.Name, - Family = item.Family, - }; - } - - public static Rune ToModel(this RuneDTO dto) - { - /*if (dto == null) - { - *//* var message = string.Format("Champion with name = {} not found", dto.Name); - throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));*//* - }*/ - return new Rune(dto.Name, dto.Family); - } - } - } -} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs deleted file mode 100644 index 9a15c1e..0000000 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RunePageMapper.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Entities; -using Model; - -namespace API_LoL_Project.Mapper -{ - public static class RunePageMapper - { - - } -} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs deleted file mode 100644 index e658fc3..0000000 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs +++ /dev/null @@ -1,13 +0,0 @@ -using DTO; -using Entities; -using Model; - -namespace API_LoL_Project.Mapper -{ - public static class SkinMapper - { - - - } -} - diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs index 5c3cd07..ac2026c 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs @@ -19,6 +19,7 @@ builder.Services.AddControllers().AddJsonOptions(options => { options.JsonSerializerOptions.Converters.Add(new ReadOnlyDictionaryConverter()); }); + builder.Services.AddEndpointsApiExplorer(); builder.Services.AddSwaggerGen(); @@ -58,6 +59,7 @@ if (app.Environment.IsDevelopment()) description.GroupName.ToUpperInvariant()); } }); + } app.UseHttpsRedirection(); diff --git a/EntityFramework_LoL/Sources/ApiMappeur/ChampionMapper.cs b/EntityFramework_LoL/Sources/ApiMappeur/ChampionMapper.cs index 43d10b6..a5ff45a 100644 --- a/EntityFramework_LoL/Sources/ApiMappeur/ChampionMapper.cs +++ b/EntityFramework_LoL/Sources/ApiMappeur/ChampionMapper.cs @@ -1,6 +1,4 @@ -using API_LoL_Project.Mapper; -using ApiMappeur; -using DTO; +using DTO; using Entities; using Model; diff --git a/EntityFramework_LoL/Sources/ApiMappeur/RuneMapper.cs b/EntityFramework_LoL/Sources/ApiMappeur/RuneMapper.cs index 63fb9c5..d19e07e 100644 --- a/EntityFramework_LoL/Sources/ApiMappeur/RuneMapper.cs +++ b/EntityFramework_LoL/Sources/ApiMappeur/RuneMapper.cs @@ -1,29 +1,35 @@  using DTO; using Model; +using System.Text; +using Rune = Model.Rune; - namespace API_LoL_Project.Mapper - { + +namespace ApiMappeur +{ public static class RuneMapper { public static RuneDTO ToDTO(this Rune item) { - return new RuneDTO() - { - Name = item.Name, - Family = item.Family, - }; - } + return new RuneDTO + { + Name = item.Name, + Description = item.Description, + Family = item.Family, + Icon = item.Icon, + Image = item.Image + }; + } public static Rune ToModel(this RuneDTO dto) { - /*if (dto == null) - { - *//* var message = string.Format("Champion with name = {} not found", dto.Name); - throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));*//* - }*/ - return new Rune(dto.Name, dto.Family); - } + /*if (dto == null) + { + *//* var message = string.Format("Champion with name = {} not found", dto.Name); + throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message));*//* + }*/ + return new Rune(dto.Name, dto.Family, dto.Icon, dto.Image.Base64, dto.Description); + } } } diff --git a/EntityFramework_LoL/Sources/ApiMappeur/RunePageMapper.cs b/EntityFramework_LoL/Sources/ApiMappeur/RunePageMapper.cs deleted file mode 100644 index 9d334a7..0000000 --- a/EntityFramework_LoL/Sources/ApiMappeur/RunePageMapper.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Entities; -using Model; - -namespace ApiMappeur -{ - public static class RunePageMapper - { - - } -} diff --git a/EntityFramework_LoL/Sources/ApiMappeur/RunePageMappeur.cs b/EntityFramework_LoL/Sources/ApiMappeur/RunePageMappeur.cs new file mode 100644 index 0000000..7063379 --- /dev/null +++ b/EntityFramework_LoL/Sources/ApiMappeur/RunePageMappeur.cs @@ -0,0 +1,77 @@ +using DTO; +using Shared; +using Rune = Model.Rune; +using Model; + +namespace ApiMappeur +{ + /* public static class RunePageMappeur + { + public static RunePageDTO ToDto(this RunePage runePage) + { + var runePageDTO = new RunePageDTO + { + Name = runePage.Name, + Runes = new Dictionary() + }; + foreach (var runeCategory in Enum.GetValues(typeof(Category)).Cast()) + { + var rune = runePage[runeCategory]; + if (rune != null) + { + runePageDTO.Runes[runeCategory] = rune.ToDTO(); + } + } + return runePageDTO; + } + + public static RunePage ToModel(this RunePageDTO runePageDto) + { + var entity = new RunePage(runePageDto.Name); + + foreach (var kvp in runePageDto.Runes) + { + var category = kvp.Key; + var runeDTO = kvp.Value; + var rune = new Rune(runeDTO.Name, runeDTO.Family, runeDTO.Icon, runeDTO.Image.Base64, runeDTO.Description); + entity[category] = rune; + } + + return entity;} + }*/ + + + public static class RunePageMappeur + { + public static RunePageDTO ToDto(this RunePage runePage) + { + + return new RunePageDTO() + { + Name = runePage.Name, + Runes = runePage.Runes.ToDictionary(c => c.Key.ToString(), r => r.Value.ToDTO()) + }; + } + + public static RunePage ToModel(this RunePageDTO runePageDto) + { + Category category; + Dictionary runDico = runePageDto.Runes.ToDictionary( + r => (Category)Enum.Parse(typeof(Category), r.Key), + r => r.Value.ToModel() + ); + + var runePage = new RunePage(runePageDto.Name); + foreach (var rune in runePageDto.Runes) + { + if (!Enum.TryParse(rune.Key, true, out category)) + { + continue; + } + runePage[category] = rune.Value.ToModel(); + } + + return runePage; + } + } +} diff --git a/EntityFramework_LoL/Sources/DTO/RunePageDTO.cs b/EntityFramework_LoL/Sources/DTO/RunePageDTO.cs new file mode 100644 index 0000000..4be2af9 --- /dev/null +++ b/EntityFramework_LoL/Sources/DTO/RunePageDTO.cs @@ -0,0 +1,15 @@ +using Shared; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class RunePageDTO + { + public string Name { get; set; } + public Dictionary Runes { get; set; } + } +} diff --git a/EntityFramework_LoL/Sources/DTO/SkinDto.cs b/EntityFramework_LoL/Sources/DTO/SkinDto.cs index 601cf2a..b49cb28 100644 --- a/EntityFramework_LoL/Sources/DTO/SkinDto.cs +++ b/EntityFramework_LoL/Sources/DTO/SkinDto.cs @@ -16,5 +16,17 @@ namespace DTO public ImageDTO LargeImage { get; set; } + } + public class SkinFullDto + { + public string Champion { get; set; } + + public string Name { get; set; } + public string Description { get; set; } + public string Icon { get; set; } + public float Price { get; set; } + public ImageDTO LargeImage { get; set; } + + } } diff --git a/EntityFramework_LoL/Sources/Test_Api/RunePageControllerTest.cs b/EntityFramework_LoL/Sources/Test_Api/RunePageControllerTest.cs new file mode 100644 index 0000000..4ef49eb --- /dev/null +++ b/EntityFramework_LoL/Sources/Test_Api/RunePageControllerTest.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Test_Api +{ + public class RunePageControllerTest + { + } +}