From bc5186fa9d5cfe3f10a783928b701b89ef6c414e Mon Sep 17 00:00:00 2001 From: Corentin R <76619184+Koroh63@users.noreply.github.com> Date: Sun, 26 Mar 2023 11:36:14 +0200 Subject: [PATCH] ajout logErrors --- Sources/API_LoL/Controllers/ChampionsController.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Sources/API_LoL/Controllers/ChampionsController.cs b/Sources/API_LoL/Controllers/ChampionsController.cs index 46dbcaf..afd09fa 100644 --- a/Sources/API_LoL/Controllers/ChampionsController.cs +++ b/Sources/API_LoL/Controllers/ChampionsController.cs @@ -158,6 +158,7 @@ namespace API_LoL.Controllers var champ = await ChampionsManager.GetItemsByName(champion.Name, 0, 1); if(champ.Count() != 0 && champ.FirstOrDefault().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()); @@ -170,10 +171,16 @@ namespace API_LoL.Controllers [HttpPut("name")] public async Task Put(string name, ChampionDTO championDTO) { - if(string.IsNullOrEmpty(name)) + if (string.IsNullOrEmpty(name)) + { + _logger.LogError(message: "Null paramater given for Name", "Put", "/Champion/Name", 400,"name : "+name, "champion : " + championDTO.toString, DateTime.Now); return BadRequest(); + } if(championDTO == null) + { + _logger.LogError(message: "Null paramater given for Champion", "Put", "/Champion/Name", 422, "name : " + name, "champion : " + championDTO.toString, DateTime.Now); return UnprocessableEntity(); + } var list = await ChampionsManager.GetItemsByName(name, 0, 1); if (list.Count() == 1) { @@ -187,7 +194,10 @@ namespace API_LoL.Controllers public async Task Delete(string name) { if (string.IsNullOrEmpty(name)) - return BadRequest(); + { + _logger.LogError(message: "Null paramater given for Name", "Delete", "/Champion/Name", 400, "name : " + name, DateTime.Now); + return BadRequest(); + } var list = await ChampionsManager.GetItemsByName(name, 0, 1); if(list.Count() == 1){ return Ok(await ChampionsManager.DeleteItem(list.First()));