From d416ae2183fffdb2c0d26c916f6c9a127d0fb02a Mon Sep 17 00:00:00 2001 From: dadalmeida1 Date: Mon, 13 Mar 2023 08:14:52 +0100 Subject: [PATCH 1/3] ctrl mostly good --- .../API_LoL_Project/API_LoL_Project.csproj | 2 + .../Controllers/ChampionsController.cs | 214 +++++++++++++++--- .../Controllers/Request/PageRequest.cs | 8 +- .../Controllers/Response/EndPointLink.cs | 22 ++ .../Controllers/Response/PageResponse.cs | 20 +- .../Controllers/RuneController.cs | 113 ++++++--- .../Controllers/RunePageController.cs | 7 +- .../Controllers/SkillController.cs | 4 +- .../Controllers/SkinController.cs | 18 +- .../API_LoL_Project/Mapper/ChampionMapper.cs | 18 +- .../API_LoL_Project/Mapper/ImageMappeur.cs | 23 ++ .../API_LoL_Project/Mapper/RuneMapper.cs | 2 +- .../API_LoL_Project/Mapper/SkinMapper.cs | 13 +- .../Middleware/HateosMiddleware.cs | 7 + .../API_LoL_Project/Middleware/LolResponce.cs | 18 ++ .../Sources/API_LoL_Project/Program.cs | 2 +- .../Sources/Business/Extensions.cs | 2 +- .../Sources/DTO/ChampionDTO.cs | 20 +- EntityFramework_LoL/Sources/DTO/ImageDTO.cs | 13 ++ EntityFramework_LoL/Sources/DTO/RuneDTO.cs | 5 +- EntityFramework_LoL/Sources/DTO/SkillDto.cs | 14 ++ EntityFramework_LoL/Sources/DTO/SkinDto.cs | 17 ++ .../Sources/LeagueOfLegends.sln | 6 +- 23 files changed, 470 insertions(+), 98 deletions(-) create mode 100644 EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/EndPointLink.cs create mode 100644 EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ImageMappeur.cs create mode 100644 EntityFramework_LoL/Sources/API_LoL_Project/Middleware/HateosMiddleware.cs create mode 100644 EntityFramework_LoL/Sources/API_LoL_Project/Middleware/LolResponce.cs create mode 100644 EntityFramework_LoL/Sources/DTO/ImageDTO.cs create mode 100644 EntityFramework_LoL/Sources/DTO/SkillDto.cs create mode 100644 EntityFramework_LoL/Sources/DTO/SkinDto.cs 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 f7057e6..6684108 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj +++ b/EntityFramework_LoL/Sources/API_LoL_Project/API_LoL_Project.csproj @@ -21,6 +21,8 @@ + + diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs index 48775fc..2db9d8b 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs @@ -1,17 +1,20 @@ -using API_LoL_Project.Mapper; +using API_LoL_Project.Controllers.Response; +using API_LoL_Project.Mapper; using API_LoL_Project.Middleware; using DTO; using Microsoft.AspNetCore.Mvc; using Model; using StubLib; +using System.Collections.Generic; using System.Text.Json; using System.Xml.Linq; -// 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/v{version:apiVersion}/[controller]")]*/ [Route("api/[controller]")] + /*[ApiVersion("1.0")]*/ [ApiController] public class ChampionsController : ControllerBase { @@ -30,42 +33,58 @@ namespace API_LoL_Project.Controllers - // GET: api/ + // GET: api//getAllChampions [HttpGet] - public async Task>> Get([FromQuery] Request.PageRequest request) + public async Task>> Get([FromQuery] Request.PageRequest request) { try { var totalcount = await dataManager.GetNbItems(); - if (request.count + request.index > totalcount) + if (request.count * request.index >= totalcount) { - _logger.LogWarning("No chamions found with Id"); - return BadRequest("No chamions found with Id "); + _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(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.LogInformation("Executing {Action} with parameters: {Parameters}", nameof(Get), request); ; + var champions = await dataManager.GetItems(request.index, request.count, 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.LogError("No chamions found the total count is {totalcount} ", totalcount); + return BadRequest("No chamions found : totalcount is : "+ totalcount); } - return Ok(res); + + var respList = res.Select(r => new LolResponce + ( + r, + new List + { + EndPointLink.To($"/api/[controller]/{r.Name}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(Get)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsImage)}", "self"), + EndPointLink.To($"/api/[controller]/{r.Name}/{nameof(GetChampionsByName)}", "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 Champions controller : " + e.Message); return BadRequest(e.Message); } - - } - - // GET api//5 - [HttpGet("{name}")] - public async Task> GetChampionsByName(string name) + /*// GET api//5 + [HttpGet("{id}")] + public async Task>> GetChampionsById(int name) { try { @@ -73,10 +92,11 @@ 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); ; + _logger.LogWarning("No chamions found with {name}", name); ; return NotFound(); } return Ok(res); @@ -86,6 +106,79 @@ namespace API_LoL_Project.Controllers { return BadRequest(e.Message); + } + }*/ + + // GET: api//LargeImage + [HttpGet("image/{name}")] + public async Task> GetChampionsImage(string 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());//.First*/ + ChampionFullDTO res = champion.First().toFullDTO();//.First + + if (res == null) + { + _logger.LogWarning("No chamions found with {name}", name); ; + return NotFound(); + } + + return Ok(res.LargeImage); + + } + catch (Exception e) + { + return BadRequest(e.Message); + + } + } + + + // GET api//name + [HttpGet("{name}")] + public async Task>> GetChampionsByName(string name) + { + _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name); + try + { + var totalcount = await dataManager.GetNbItemsByName(name); + if ( totalcount <= 0) + { + _logger.LogWarning("No chamions found with this name {name}", name); ; + return BadRequest("No chamions found with this name: " + name); + } + + var champion = await dataManager.GetItemsByName(name, 0, totalcount); + /* IEnumerable res = champion.Select(c => c.toFullDTO());//.First*/ + if (champion.Count() <= 0 || champion == null ) + { + _logger.LogWarning("No chamions found with {name}", name); ; + return NotFound("No chamions found with"+name); + } + ChampionFullDTO res = champion.First().toFullDTO();//.First + + + 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("Somthing goes wrong caching the Champions controller : " + e.Message); + } } @@ -96,33 +189,48 @@ namespace API_LoL_Project.Controllers { try { - var newChampion = value.toModel(); + var newChampion = value.ToModel(); await dataManager.AddItem(newChampion); - return CreatedAtAction(nameof(Get), newChampion) ; + // can we check with a method + //var savedChampions = await dataManager.GetItemsByName(newChampion.name, 0, await dataManager.GetNbItems()) + /*if (savedChampions.Count() >= 0 || res == null) + { + _logger.LogWarning("No chamions found "); + return BadRequest("No chamions found "); + }*/ + _logger.LogInformation("Sucessfully saved Champions : " + newChampion.Name); + + return CreatedAtAction(nameof(Get), newChampion); } catch (Exception e) { + _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message); return BadRequest(e.Message); } } - + // should change for id cause model implementation use filteringbyName to getItemByNAme and it use substring // PUT api//5 [HttpPut("{name}")] public async Task Put(string name, [FromBody] ChampionDTO value) { - - try { + _logger.LogInformation("Executing {Action} with name : {championName}", nameof(Put), name); var champion = await dataManager .GetItemsByName(name, 0, await dataManager.GetNbItems()); - await dataManager.UpdateItem(champion.First(), value.toModel()); + if (champion == null) + { + _logger.LogError("No chamions found with {name} in the dataBase", name); ; + return NotFound(); + } + await dataManager.UpdateItem(champion.First(), value.ToModel()); return Ok(); } - catch(Exception e) + catch (Exception e) { + _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message); return BadRequest(e.Message); } } @@ -133,20 +241,23 @@ namespace API_LoL_Project.Controllers { try { + _logger.LogInformation("Executing {Action} with name : {championName}", nameof(Delete), name); var champion = await dataManager .GetItemsByName(name, 0, await dataManager.GetNbItems()); if (champion != null) await dataManager.DeleteItem(champion.First()); else { + _logger.LogWarning("No chamions found with {name}", name); ; return NotFound(); } return Ok(); } catch (Exception e) { + _logger.LogError("Somthing goes wrong caching the Champions controller : " + e.Message); return BadRequest(e.Message); } - + } /* [HttpGet] @@ -159,17 +270,48 @@ namespace API_LoL_Project.Controllers }*/ [HttpGet("/{name}/skins")] - public async Task> GetChampionsSkins(string name) + public async Task> GetChampionsSkins(string name) { + _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkins), name); var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()); + if (champions == null) + { + _logger.LogWarning("No chamions found with {name}", name); ; + return NotFound(); + } //skinsDTO - IEnumerable res = champions.First().Skins; - + IEnumerable res = champions.First().Skins.Select(c => c.ToDto()); + if (res == null) + { + _logger.LogWarning("No skins found for {name}", name); ; + return NotFound(); + } return Ok(res); } - [HttpGet("/{name}/skills")] - public async Task> GetChampionsSkills(string name) + /* [HttpGet("/{name}/skills")] + public async Task> GetChampionsSkills(string name) + { + _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkills), name); + var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()); + if (champions == null) + { + _logger.LogWarning("No chamions found with {name}", name); ; + return NotFound(); + } + //skinsDTO + IEnumerable res = champions.First().Skills.to; + if (res == null) + { + _logger.LogWarning("No skins found for {name}", name); ; + return NotFound(); + } + + return Ok(res); + }*/ + + [HttpPost("/{name}/skills")] + public async Task>> AddChampionsSkills(string name) { var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()); //SkillDTO @@ -187,4 +329,6 @@ namespace API_LoL_Project.Controllers }*/ } + + } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs index 1950fa3..3d7cfb4 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs @@ -5,13 +5,13 @@ //max leght public string? orderingPropertyName { get; set; } = null; public bool? descending { get; set; } = false; - const int maxPageSize = 50; - public int PageNumber { get; set; } = 1; + // const int maxPageSize = 50; + // public int PageNumber { get; set; } = 1; public int index { get; set; } = 1; public int count { get; set; } = 1; - +/* //max lentght private int _pageSize; public int PageSize @@ -24,6 +24,6 @@ { _pageSize = (value > maxPageSize) ? maxPageSize : value; } - } + }*/ } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/EndPointLink.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/EndPointLink.cs new file mode 100644 index 0000000..3ef451d --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/EndPointLink.cs @@ -0,0 +1,22 @@ +namespace API_LoL_Project.Controllers.Response +{ + public class EndPointLink + { + public string Href { get; set; } + public string Rel { get; set; } + public string Method { get; set; } + public EndPointLink() + { + } + public EndPointLink(string href, string rel, string method) + { + Href = href; + Rel = rel; + Method = method; + } + public static EndPointLink To(string href, string rel = "self", string method = "GET") + { + return new EndPointLink { Href = href, Rel = rel, Method = method }; + } + } +} 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..62a21bc 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Response/PageResponse.cs @@ -1,6 +1,22 @@ -namespace API_LoL_Project.Controllers.Response +using API_LoL_Project.Middleware; + +namespace API_LoL_Project.Controllers.Response { - public class PageResponse + public class PageResponse { + public IEnumerable> Data { get; set; } + public int Index { get; set; } = 1; + public int TotalCount { get; set; } = 1; + public int Count { get; set; } = 1; + + + public PageResponse(IEnumerable> data, int indexRequested, int countRequested, int totalCount) + { + this.Data = data; + this.Index = indexRequested; + this.TotalCount = totalCount; + this.Count = countRequested; + } } } + diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs index 7b9a2f2..9ec17e0 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 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 @@ -12,40 +14,71 @@ namespace API_LoL_Project.Controllers [ApiController] public class RuneController : ControllerBase { - public IRunesManager runesManager; + public IRunesManager dataManager; // you should create a custom logger to be prety private readonly ILogger _logger; public RuneController(IDataManager dataManager, ILogger logger) { - this.runesManager = dataManager.RunesMgr; + this.dataManager = dataManager.RunesMgr; this._logger = logger; } - /*// GET: api/ + // GET: api/ [HttpGet] - public async Task> Get() + public async Task>> GetAllRunes([FromQuery] Request.PageRequest request) { try { - var runes = await runesManager.GetItems(0, await runesManager.GetNbItems()); + 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()); - return Ok(res); + 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.LogInformation("About get at {e.message}", DateTime.UtcNow.ToLongTimeString()); + _logger.LogError("Somthing goes wrong caching the Rune controller : " + e.Message); return BadRequest(e.Message); } - }*/ + } + // GET: api/ - [HttpGet] + /* [HttpGet] public async Task>> Get([FromQuery] Request.PageRequest request) { try @@ -54,12 +87,12 @@ namespace API_LoL_Project.Controllers 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) ; + 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)); + + 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) { @@ -77,9 +110,45 @@ namespace API_LoL_Project.Controllers } +*/ + + [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 + /* // GET api//5 [HttpGet("{id}")] public string Get(int id) { @@ -97,24 +166,10 @@ namespace API_LoL_Project.Controllers } - } + }*/ // POST api/ - [HttpPost] - public void Post([FromBody] string value) - { - try - { - await dataManager.AddItem(value.toModel()); - return Ok(); - } - catch () - { - new HttpException(400, 'Cannot create rune') - } - - - } + // PUT api//5 [HttpPut("{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..271d180 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RunePageController.cs @@ -1,4 +1,5 @@ -using Microsoft.AspNetCore.Mvc; +using DTO; +using Microsoft.AspNetCore.Mvc; // For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860 @@ -8,7 +9,7 @@ namespace API_LoL_Project.Controllers [ApiController] public class RunePageController : ControllerBase { - // GET: api/ + /* // GET: api/ [HttpGet] public async Task>> Get([FromQuery] Request.PageRequest request) { @@ -65,6 +66,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 index 950897f..042bc7e 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkillController.cs @@ -8,7 +8,7 @@ namespace API_LoL_Project.Controllers [ApiController] public class SkillController : ControllerBase { - // GET: api/ + /* // GET: api/ [HttpGet] public async Task>> Get([FromQuery] Request.PageRequest request) { @@ -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/SkinController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs index db11f8d..9f41870 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/SkinController.cs @@ -1,4 +1,6 @@ -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 @@ -8,13 +10,21 @@ namespace API_LoL_Project.Controllers [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 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,7 +33,7 @@ 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)); + 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) { @@ -65,6 +75,6 @@ namespace API_LoL_Project.Controllers [HttpDelete("{id}")] 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 a7c1e89..8d48d22 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs @@ -10,9 +10,10 @@ namespace API_LoL_Project.Mapper { if (item == null) { - var message = string.Format("Champion with name = {} nhhoddt found", item.Name); + var message = string.Format("Champion cannot be empty"); /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); */ + throw new Exception(message); } return new ChampionDTO() { Name = item.Name, @@ -35,9 +36,11 @@ namespace API_LoL_Project.Mapper { if (item == null) { - var message = string.Format("Champion with name = {} nhhoddt found", item.Name); + var message = string.Format("Champion with name = {} not found", item.Name); /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); */ + throw new Exception(message); + } return new ChampionFullDTO() { @@ -45,8 +48,8 @@ namespace API_LoL_Project.Mapper Bio = item.Bio, Characteristics = item.Characteristics, skills = item.Skills, - skins = item.Skins, - LargeImage = item.Image + skins = item.Skins.Select(i => i.ToDto()), + LargeImage = item.Image.ToDTO() }; @@ -57,9 +60,12 @@ namespace API_LoL_Project.Mapper { if (dto == null) { - var message = string.Format("Champion with name = {} nhhoddt found", dto.Name); + var message = string.Format("Champion cannot be empty"); /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); - */} + */ + throw new Exception(message); + + } return new(dto.Name); } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ImageMappeur.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ImageMappeur.cs new file mode 100644 index 0000000..31f13ab --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ImageMappeur.cs @@ -0,0 +1,23 @@ +using DTO; +using Model; + +namespace API_LoL_Project.Mapper +{ + public static class ImageMappeur + { + public static ImageDTO ToDTO(this LargeImage item) + { + if (item == null) + { + var message = string.Format("Image cannot be empty"); + /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); + */ + } + return new ImageDTO() + { + base64 = item.Base64 + }; + } + + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs index 3b2b752..69b1fb3 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/RuneMapper.cs @@ -24,4 +24,4 @@ } } -} + diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs index ad5a96b..4293ba1 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/SkinMapper.cs @@ -17,7 +17,18 @@ namespace API_LoL_Project.Mapper throw new NotImplementedException(); } + public static SkinDto ToDto(this Skin item) + { + return new SkinDto() + { + Name = item.Name, + Description = item.Description, + Icon = item.Icon, + Price = item.Price + }; + + } } } -} + diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/HateosMiddleware.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/HateosMiddleware.cs new file mode 100644 index 0000000..7207f72 --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/HateosMiddleware.cs @@ -0,0 +1,7 @@ +namespace API_LoL_Project.Middleware +{ + public class HateosMiddleware + { + + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/LolResponce.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/LolResponce.cs new file mode 100644 index 0000000..22b7703 --- /dev/null +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Middleware/LolResponce.cs @@ -0,0 +1,18 @@ +using API_LoL_Project.Controllers.Response; +using System.Net; + +namespace API_LoL_Project.Middleware +{ + public class LolResponce + { + public T Data { get; set; } + public List Links { get; set; } = null; + + + public LolResponce(T data , List? links) + { + this.Data = data; + this.Links = links; + } + } +} diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs index 79eb2d3..f4c432c 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Program.cs @@ -13,7 +13,7 @@ builder.Services.AddSwaggerGen(); builder.Services.AddSingleton(); var app = builder.Build(); - +// à enlever // Configure the HTTP request pipeline. if (app.Environment.IsDevelopment()) { diff --git a/EntityFramework_LoL/Sources/Business/Extensions.cs b/EntityFramework_LoL/Sources/Business/Extensions.cs index 9f99257..ac81eaa 100644 --- a/EntityFramework_LoL/Sources/Business/Extensions.cs +++ b/EntityFramework_LoL/Sources/Business/Extensions.cs @@ -22,7 +22,7 @@ namespace Business : temp.OrderBy(item => prop.GetValue(item)); } } - return temp.Skip(index * count).Take(count) + return temp.Skip(index * count).Take(count); } } } diff --git a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs index 5d0e9f6..75db492 100644 --- a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs +++ b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs @@ -1,23 +1,31 @@ using Model; +using System.Collections.ObjectModel; +using System.ComponentModel.DataAnnotations; 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 { + /*[Required(ErrorMessage = "Name is required")] + [StringLength(60, ErrorMessage = "Name can't be longer than 60 characters")]*/ 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 ImageDTO LargeImage { get; set; } - public IEnumerable skins { get; set; } + public IEnumerable skins { get; set; } public IEnumerable skills { get; set; } } + + } \ No newline at end of file diff --git a/EntityFramework_LoL/Sources/DTO/ImageDTO.cs b/EntityFramework_LoL/Sources/DTO/ImageDTO.cs new file mode 100644 index 0000000..3b5cec1 --- /dev/null +++ b/EntityFramework_LoL/Sources/DTO/ImageDTO.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DTO +{ + public class ImageDTO + { + public string base64 { get; set; } + } +} diff --git a/EntityFramework_LoL/Sources/DTO/RuneDTO.cs b/EntityFramework_LoL/Sources/DTO/RuneDTO.cs index 495f618..64b8989 100644 --- a/EntityFramework_LoL/Sources/DTO/RuneDTO.cs +++ b/EntityFramework_LoL/Sources/DTO/RuneDTO.cs @@ -1,4 +1,5 @@ using Model; +using Shared; using System; using System.Collections.Generic; using System.Linq; @@ -13,9 +14,9 @@ namespace DTO public string Description { get; set; } - public RuneFamily Family { get; set; } + public RuneFamily Family { get; set; } - public string Icon { get; set; } + public string Icon { get; set; } public LargeImage Image { 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/LeagueOfLegends.sln b/EntityFramework_LoL/Sources/LeagueOfLegends.sln index ef88d8c..dc80334 100644 --- a/EntityFramework_LoL/Sources/LeagueOfLegends.sln +++ b/EntityFramework_LoL/Sources/LeagueOfLegends.sln @@ -25,7 +25,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Entities", "Entities\Entiti EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Test_Api", "Test_Api\Test_Api.csproj", "{C35C38F6-5774-4562-BD00-C81BCE13A260}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Business", "Business\Business.csproj", "{A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -61,6 +61,10 @@ Global {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Debug|Any CPU.Build.0 = Debug|Any CPU {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.ActiveCfg = Release|Any CPU {C463E2E1-237A-4339-A4C4-6EA3BE7002AE}.Release|Any CPU.Build.0 = Release|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C35C38F6-5774-4562-BD00-C81BCE13A260}.Release|Any CPU.Build.0 = Release|Any CPU {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Debug|Any CPU.Build.0 = Debug|Any CPU {A447B0BE-62AE-4F66-B887-D1F3D46B0DB3}.Release|Any CPU.ActiveCfg = Release|Any CPU From 9bc670215e5c5c639db7ba443eded5de2391a93d Mon Sep 17 00:00:00 2001 From: dadalmeida1 Date: Mon, 13 Mar 2023 15:59:44 +0100 Subject: [PATCH 2/3] count endpoints --- .../Controllers/ChampionsController.cs | 75 +++++++++---------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs index 2db9d8b..3bf7f28 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/ChampionsController.cs @@ -52,7 +52,7 @@ namespace API_LoL_Project.Controllers if (res.Count() <= 0 || res == null) { _logger.LogError("No chamions found the total count is {totalcount} ", totalcount); - return BadRequest("No chamions found : totalcount is : "+ totalcount); + return BadRequest("No chamions found : totalcount is : " + totalcount); } var respList = res.Select(r => new LolResponce @@ -69,8 +69,8 @@ namespace API_LoL_Project.Controllers } )); - var pageResponse = new PageResponse(respList,request.index,request.count,totalcount); - + var pageResponse = new PageResponse(respList, request.index, request.count, totalcount); + return Ok(pageResponse); } catch (Exception e) @@ -126,7 +126,7 @@ namespace API_LoL_Project.Controllers _logger.LogWarning("No chamions found with {name}", name); ; return NotFound(); } - + return Ok(res.LargeImage); } @@ -142,11 +142,11 @@ namespace API_LoL_Project.Controllers [HttpGet("{name}")] public async Task>> GetChampionsByName(string name) { - _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name); + _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsByName), name); try { var totalcount = await dataManager.GetNbItemsByName(name); - if ( totalcount <= 0) + if (totalcount <= 0) { _logger.LogWarning("No chamions found with this name {name}", name); ; return BadRequest("No chamions found with this name: " + name); @@ -154,14 +154,14 @@ namespace API_LoL_Project.Controllers var champion = await dataManager.GetItemsByName(name, 0, totalcount); /* IEnumerable res = champion.Select(c => c.toFullDTO());//.First*/ - if (champion.Count() <= 0 || champion == null ) + if (champion.Count() <= 0 || champion == null) { _logger.LogWarning("No chamions found with {name}", name); ; - return NotFound("No chamions found with"+name); + return NotFound("No chamions found with" + name); } ChampionFullDTO res = champion.First().toFullDTO();//.First - + var links = new List { EndPointLink.To($"/api/[controller]/{res.Name}", "self"), @@ -169,7 +169,7 @@ namespace API_LoL_Project.Controllers EndPointLink.To($"/api/[controller]/{res.Name}/", "self") }; - var response = new LolResponce(res,links); + var response = new LolResponce(res, links); return Ok(response); } @@ -289,26 +289,26 @@ namespace API_LoL_Project.Controllers return Ok(res); } - /* [HttpGet("/{name}/skills")] - public async Task> GetChampionsSkills(string name) - { - _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkills), name); - var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()); - if (champions == null) - { - _logger.LogWarning("No chamions found with {name}", name); ; - return NotFound(); - } - //skinsDTO - IEnumerable res = champions.First().Skills.to; - if (res == null) - { - _logger.LogWarning("No skins found for {name}", name); ; - return NotFound(); - } - - return Ok(res); - }*/ + /* [HttpGet("/{name}/skills")] + public async Task> GetChampionsSkills(string name) + { + _logger.LogInformation("Executing {Action} with name : {championName}", nameof(GetChampionsSkills), name); + var champions = await dataManager.GetItemsByName(name, 0, await dataManager.GetNbItems()); + if (champions == null) + { + _logger.LogWarning("No chamions found with {name}", name); ; + return NotFound(); + } + //skinsDTO + IEnumerable res = champions.First().Skills.to; + if (res == null) + { + _logger.LogWarning("No skins found for {name}", name); ; + return NotFound(); + } + + return Ok(res); + }*/ [HttpPost("/{name}/skills")] public async Task>> AddChampionsSkills(string name) @@ -320,15 +320,14 @@ namespace API_LoL_Project.Controllers return Ok(res); } - /*[HttpGet("/{name}/skins")] - public async Task NbChampions() + // degradation du modèle cleitn ell est dédié au cliens + [HttpGet("/count")] + public async Task> NbChampions() { - var champions = await dataManager.GetItems(0, await dataManager.GetNbItems()); - IEnumerable res = champions.Select(c => c.toDTO()); - return Ok(res); + var nbChampions = await dataManager.GetNbItems(); + return Ok(nbChampions); + } - }*/ } - - } + From 5bd1f568dc9f8639a1e8a53bdab65725bd40d15e Mon Sep 17 00:00:00 2001 From: dadalmeida1 Date: Tue, 14 Mar 2023 18:26:17 +0100 Subject: [PATCH 3/3] fix all --- .../Controllers/Request/PageRequest.cs | 20 +-- .../Controllers/RuneController.cs | 158 +++++++++--------- .../API_LoL_Project/Entities.LolDatabase.db | Bin 4096 -> 126976 bytes .../Entities.LolDatabase.db-shm | Bin 32768 -> 0 bytes .../Entities.LolDatabase.db-wal | Bin 127752 -> 0 bytes .../API_LoL_Project/Mapper/ChampionMapper.cs | 11 ++ .../Sources/DTO/ChampionDTO.cs | 4 + 7 files changed, 97 insertions(+), 96 deletions(-) delete mode 100644 EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm delete mode 100644 EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs index c4c464c..b4f35e5 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/Request/PageRequest.cs @@ -4,25 +4,9 @@ { public string? orderingPropertyName { get; set; } = null; public bool? descending { get; set; } = false; - // const int maxPageSize = 50; - // public int PageNumber { get; set; } = 1; - - public int index { get; set; } = 1; + public int index { get; set; } = 0; public int count { get; set; } = 1; -/* - //max lentght - private int _pageSize; - public int PageSize - { - get - { - return _pageSize; - } - set - { - _pageSize = (value > maxPageSize) ? maxPageSize : value; - } - }*/ + } } diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs index 9ec17e0..2bef43b 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Controllers/RuneController.cs @@ -12,6 +12,7 @@ namespace API_LoL_Project.Controllers { [Route("api/[controller]")] [ApiController] + public class RuneController : ControllerBase { public IRunesManager dataManager; @@ -28,7 +29,7 @@ namespace API_LoL_Project.Controllers - // GET: api/ + /*// GET: api/ [HttpGet] public async Task>> GetAllRunes([FromQuery] Request.PageRequest request) { @@ -74,102 +75,103 @@ namespace API_LoL_Project.Controllers return BadRequest(e.Message); } - } + } + */ // GET: api/ - /* [HttpGet] - public async Task>> Get([FromQuery] Request.PageRequest request) - { - try + /* [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) { - 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) + try { - _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); - } + 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") + }; - } -*/ - - [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(); + var response = new LolResponce(res, links); + return Ok(response); - if (res == null) - { - _logger.LogWarning("No runes found with {name}", name); ; - return NotFound(); } - var links = new List + catch (Exception e) { - 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); + _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) - { + /* // 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); - } + new HttpException(400, 'Cannot get rune :' + e.message); + } - }*/ + }*/ // POST api/ - + // PUT api//5 [HttpPut("{id}")] diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db index 81dae899f351f43f4e0ef4b510c62a2f6b578c80..8073a2f0b7bfee2039f95d367a7044dc8221a408 100644 GIT binary patch literal 126976 zcmeI5TW=f36~}i;i7QH`*0!vy>BQBVLSVD9TGNs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6@l$6L!Q(;3Z0p*{vqzB5 z+~D0b3&=t5omK6jyPFMzoye5NwJfuz1FsPFHWS^ltDxStzHdhsgpYY{aXZO#IFb^n z{RT4h5Gzwbg=6)=*nsZ&PsW9aX|D{%geQDJfWQCWZ%Z2J0|Fob0w4eaAOHd&00JNY z0w4eaegatk`WHv;DW|NEBV|HFT~-*kgMAOHd& z00JNY0w4eaAOHd&00JOzzzOt388#A)GI4YL|B&Io;U6AwCQu&)KmY_l00ck)1V8`; zKmY_l00j02fxhT4o0s2KBJpT4o^7seG!^{)|Nby7v;YAR009sH0T2KI5C8!X009sH zfo=rw_y67KAPodS00ck)1V8`;KmY_l00ck)1okum{Qdu)HXnos0T2KI5C8!X009sH z0T2KI5CDNL1VaA)KSI9x58waSg&UGU00ck)1V8`;KmY_l00ck)1VCVK5^&D{{|9Ng B$i)Bv delta 26 gcmZp8z}}!RL7J73fq{W>;zD~MLoZ%x(}p?x09-=`4UZN&m5;bE?w6(Ff)MxOe>{6!^L0fx4tGtL<8%S?q_KFfxo`BUk z--5-!F#I!o)2}_bKbT6UpS!kKuj%dG+4<%5$*-%MpT~Fmhd-8%zCS*EJH43v=jZED zf0AcD{gaos|Gwn=XR2?iv(>rke08Dvwz^ndsxDXGRo_=vs;kwt>U#A<^<#CTx>?<- zeyUEY+ttt2o$8nB*XnLHze@-ZAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N z0t5&UAV7cs0RjXF5FkK+009C72oNAZfB*pk1PBlyK!5-N0f%eKTnh$hw^LC6Hx5X%Wb-qVy$@O-pGJ z$fBt9C6F~&X%WbluJk349b;(`$cnV|C1An3_5aL%x)2ysAeRG#z?cHLnIQzm6v(w0 zAuy&u?j#9;F$HoVObCoAklT1dU`&Brg%ko~3gjND5ExS+mw<)9m;$+hEd<6C$n|$= G5%>+$3@{!5 diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal b/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal deleted file mode 100644 index ea04235c627316c1ed1f630e6db804cf8a98ba3e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 127752 zcmeI5e{37)dB=IA#1kb`XIqlbbZqNPIkPoct?5XygVk^->gX|2WSf+0D;dCDsEf>* zB2|*gB4_m`S%HJrLz|_;h5_Bs3@%on>snxc>__^;HHH>Ti!MzH3~>>s+lnAfJY-v% z6!nVkeedo)-g`XK7Hlk)^d)TmxcArde4gih-{&6Qi3fi_xa1rBx2-4h8d z*Y_T}y5*IxUwQW3ZzRbf!FfFQ{<#w!zx}`$GbhILRb6?!RG!tU%6+7@-|u@+QAk}s z`QJ<1SdY!*wS|2kuSS24&t7l+z7J)$wbIJcOXS>jYsuL zuAHB%=1WCaAFM_y*Rbe#IiDj#6XC|~p;@!U8Etls^qMS{_54h6OkZf!|12Ssnr5X$ zdaDbk4oORgY|iSolJy!Oc`U7_j!sYomAz4q8vR7rq?%SI5^6??+MN-YCdPi{*n~2w zj;n-rBA!XaN7ZK16twb;o~H^_vMHtqF9bWxkL+kj$0q9chui!6HwWdzaw9J?jF^oX zFI^WRk|+-h2v6q?Um=>5wOmy%=PT8GuHyQ*k@p{0X;V*Hu{l4g73PUg5YJPOs%f`d zIBiP&vQ83*hcc7wQ#=jnZ5CIDAAq|MGalX;luryaGNW6>nCrl%<^5q%K5|63STanT zusq&eI5KDRg@XCEVL>Nv?uPYhhG$hO9%~8n0Au7P61`pkWRfGhRBD(xNE$_6o}t7HAk@9St$eH*Gv=`}m4zJ6d@VAIX}{#;Hvd>#P*!^z&4=2sG&V3PhZcuhML7}?mQ=$I=C)uy2YCzF zJI0F656Je!?aa6D?HRhaO)kuNM15rH4+Mkqkw_y|O<9egmIxp&_5=)PTU@ZGv$4ig zS2W(V@T%I!YtB};9e7P_qc2Z&Jyr&yM69Kmy=*D6#+)%aZ(ZyaM7gg|SZXy?aZF&x zTR*RkqhtjNajm>&k5lmKXTkroL zHLn-=u21^zDpMTdf&d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z48-wzRfktL@ix_hq*tEPqEXqfY2p3C+ zX%m*mn+r$gY`#!1-!?4hVIE+N+@ylbw5-cIv7-uaWLDAanpoR0 zP`|g8S(CcHJ?w2s%uhddamO;*OXujq zTiZIU&CkPU$Wp^=>K>VQNq&6dlFq?y%P0B%9d5~Y?Q#OXkoN<-teGo#s7`jy1h;~? zM6*@P+V3b)-aDN|yjXS#6^m|T^&2Sh&r=(M@>%uv{4;F@OQvsST`tO(hL?syM#!{$ z)bLU&O~rU>=l#w&R&y{9zjB96Rttw?u!Zo}Ayb-&k<@1M1rqZ#*a)L6F0cZ(hGCB( zN7fN9+?7D1y;-1P4jD6EI+oI+DEIaX%M})A7-1a^G0Zn@JZby*ifB7pc@Q7Tmsohn z&+(`;IISU!CJI`ma_8)AsqQxaSX)q5dmGJ%+ORY>Fe!%?hg(HC5)qbE!w%-QU_J+V z3)nlxip~$n_QdVXx9{y4y0=X(%y~q8WaCntPjx+32BJi)rJ22KDYC|#F*=i`0uTNNNHB@m- zV8>fOua2W+1qyMkyk?J9(eEE}O(3GwusO@i z6z0sX*(X#r=B^s|)XC+l;L(N2$W@PumZ-CEwEv7O%EP_FV#pz)87MNdkdDj)+q`7q z>)Jz`hj|mlwuthhM})qP3LX;_uZmQc$ztVso~jZG~0V2>#0 zRAEu~mYKPL!@-Q8Ej7&#!Pnb*3(@)7{ONSP_jSn6^NwPc}1B8<#i!9J9nTpteMAsJ;BNoT2-GZl^dTWyK;(N z(l`QMYZ^0#R^GARM=Mcj1Bmie|KDnnD#_xP`=Aw z9FTy1D-G&dUf`v%k(AHmu%IkW%)5C8!X009sH0T2KI5C8!X z0D)T&*g?x#UZD7)neOhF{_`>1M{o;jCIpnVZ diff --git a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs index ab56601..66fc22c 100644 --- a/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs +++ b/EntityFramework_LoL/Sources/API_LoL_Project/Mapper/ChampionMapper.cs @@ -54,7 +54,18 @@ namespace API_LoL_Project.Mapper } + public static Champion ToModel(this ChampionFullDTO dto) + { + if (dto == null) + { + var message = string.Format("Champion cannot be empty"); + /*throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.NotFound, message)); + */ + throw new Exception(message); + } + return new(dto.Name);// dto.Class, dto.Icon, + } public static Champion ToModel(this ChampionDTO dto) { if (dto == null) diff --git a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs index e0b4a1a..db3a32c 100644 --- a/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs +++ b/EntityFramework_LoL/Sources/DTO/ChampionDTO.cs @@ -19,6 +19,10 @@ namespace DTO [StringLength(60, ErrorMessage = "Name can't be longer than 60 characters")]*/ public string Name { get; set; } public string Bio { get; set; } + + /* public ClassChampionDto {get; set;}*/ + /* public IconDto {get; set;}*/ + public ReadOnlyDictionary Characteristics { get; set; } public ImageDTO LargeImage { get; set; }