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 81dae89..8073a2f 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 deleted file mode 100644 index fbf3991..0000000 Binary files a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-shm and /dev/null 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 deleted file mode 100644 index ea04235..0000000 Binary files a/EntityFramework_LoL/Sources/API_LoL_Project/Entities.LolDatabase.db-wal and /dev/null differ 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; }