From 5d7002c8e8228b9dd40af82d12711d2bbce125ca Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Sun, 26 Mar 2023 14:59:33 +0200 Subject: [PATCH] add all logs --- .../Controllers/ChampionsController.cs | 63 +++++++++++++++---- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index afd09fa..2c35997 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -40,6 +40,7 @@ namespace API_LoL.Controllers [HttpGet("count")] public async Task GetCount() { + _logger.LogInformation(message: "count returned", "Get", "/Champion/Count", 200, DateTime.Now); return Ok(ChampionsManager.GetNbItems()); } @@ -56,33 +57,46 @@ namespace API_LoL.Controllers var list = await ChampionsManager.GetItemsByName(name, index, size); if (list.Count() != 0) { + _logger.LogInformation(message: "Champion returned by name", "Get", "/Champion", 200, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now); return Ok(list.Select(champion => champion?.ToDTO())); } - else { return NoContent(); } + else { + _logger.LogInformation(message: "No Champion found by name", "Get", "/Champion", 204, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now); + return NoContent(); } } else if(!string.IsNullOrEmpty(skill)) { var list = await ChampionsManager.GetItemsBySkill(skill, index, size); if (list.Count() != 0) { + _logger.LogInformation(message: "Champion returned by skill", "Get", "/Champion", 200, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now); return Ok(list.Select(champion => champion?.ToDTO())); } - else { return NoContent(); } + else { + _logger.LogInformation(message: "No Champion found by skill", "Get", "/Champion", 204, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now); + return NoContent(); } } else if(!string.IsNullOrEmpty (characteristic)) { var list = await ChampionsManager.GetItems(index, size); if (list.Count() != 0) { + _logger.LogInformation(message: "Champion returned by characteristic", "Get", "/Champion", 200, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now); return Ok(list.Select(champion => champion?.ToDTO())); } - else { return NoContent(); } + else { + _logger.LogInformation(message: "No Champion found by char", "Get", "/Champion", 204, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now); + return NoContent(); } } else { var list = await ChampionsManager.GetItems(index, size); if (list.Count() != 0) { + _logger.LogInformation(message: "Champion returned default", "Get", "/Champion", 200, "name : " + name, "skill : " + skill, "characteristic : " + characteristic, "index : " + index, "size : " + size, DateTime.Now); return Ok(list.Select(champion => champion?.ToDTO())); } - else { return NoContent(); } + else { + _logger.LogInformation(message: "No Champion found Default", "Get", "/Champion", 204, "name : " + name,"skill : " + skill,"characteristic : "+ characteristic,"index : "+index,"size : "+size, DateTime.Now); + return NoContent(); + } } } @@ -97,9 +111,13 @@ namespace API_LoL.Controllers var list = await ChampionsManager.GetItemsByName(name, 0, 1); if (list.Count() == 1) { + _logger.LogInformation(message: "Champion found", "Get", "/Champion/Name", 20, "name : " + name, DateTime.Now); return Ok(list.Select(champion => champion?.ToDTO()).First()); } - else { return NoContent(); } + else { + _logger.LogInformation(message: "No Champion found", "Get", "/Champion/Name", 204, "name : " + name, DateTime.Now); + return NoContent(); + } } @@ -120,9 +138,16 @@ namespace API_LoL.Controllers var skins = await SkinsManager.GetItemsByChampion(list.First(), 0, nb); return Ok(skins.Select(skin => skin?.ToDTO())); } - else { return NoContent(); } + else { + _logger.LogInformation(message: "No Skin found found", "Get", "/Champion/Name/Skins", 204, "name : " + name, DateTime.Now); + return NoContent(); } + } + else { + _logger.LogInformation(message: "No Champion found", "Get", "/Champion/Name/Skins", 204, "name : " + name, DateTime.Now); + + return NoContent(); } - else { return NoContent(); } + } //[HttpGet("name/skills")] @@ -155,13 +180,18 @@ namespace API_LoL.Controllers } else { - var champ = await ChampionsManager.GetItemsByName(champion.Name, 0, 1); - if(champ.Count() != 0 && champ.FirstOrDefault().Name == champion.Name) + var list = await ChampionsManager.GetItemsByName(champion.Name, 0, 1); + Champion champ = list.FirstOrDefault(); + if (champ != null) { - _logger.LogError(message: "Champion with this id already exists", "Post", "/Champion", 409, "champion : " + champion.toString, DateTime.Now); - return Conflict(champion); + if(champ.Name == champion.Name) + { + _logger.LogError(message: "Champion with this id already exists", "Post", "/Champion", 409, "champion : " + champion.toString, DateTime.Now); + return Conflict(champion); + } } await ChampionsManager.AddItem(champion.ToChampion()); + _logger.LogInformation(message: "Champion created", "Post", "Champion/Name", 201, "champion : " + champion.toString, DateTime.Now); return CreatedAtAction("Post",champion); } @@ -184,9 +214,13 @@ namespace API_LoL.Controllers var list = await ChampionsManager.GetItemsByName(name, 0, 1); if (list.Count() == 1) { + _logger.LogInformation(message: "Champion updated", "Put", "Champion/Name", 200, "name : " + name, "champion : " + championDTO.toString, DateTime.Now); return Ok(ChampionsManager.UpdateItem(list.First(), championDTO.ToChampion())); } - else { return NoContent(); } + else { + _logger.LogInformation(message: "No champion Found", "Put", "/Champion/Name", 204, "name : " + name, "champion : " + championDTO.toString, DateTime.Now); + return NoContent(); + } } // DELETE api//5 @@ -200,8 +234,11 @@ namespace API_LoL.Controllers } var list = await ChampionsManager.GetItemsByName(name, 0, 1); if(list.Count() == 1){ + _logger.LogInformation(message: "Champion Deleted", "Delete", "/Champion/Name", 200, "name : " + name, DateTime.Now); return Ok(await ChampionsManager.DeleteItem(list.First())); - }else { return NoContent(); } + }else { + _logger.LogInformation(message: "No champion Found", "Delete", "/Champion/Name", 204, "name : " + name, DateTime.Now); + return NoContent(); } } } }