From 384ae84ca120a22d0ca47e8fa2a7c9ef004d808d Mon Sep 17 00:00:00 2001 From: "victor.gaborit" Date: Fri, 8 Mar 2024 09:19:05 +0100 Subject: [PATCH] =?UTF-8?q?ajout=20d'un=20exception=20personnalis=C3=A9e?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- API_SQLuedo/API/API.csproj | 1 + API_SQLuedo/API/Controllers/UsersController.cs | 5 +++-- API_SQLuedo/API_SQLuedo.sln | 16 +++++++++++----- API_SQLuedo/Services/Services.csproj | 1 + API_SQLuedo/Services/UserDataService.cs | 3 ++- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/API_SQLuedo/API/API.csproj b/API_SQLuedo/API/API.csproj index 7bd07a9..c4154ca 100644 --- a/API_SQLuedo/API/API.csproj +++ b/API_SQLuedo/API/API.csproj @@ -26,6 +26,7 @@ + diff --git a/API_SQLuedo/API/Controllers/UsersController.cs b/API_SQLuedo/API/Controllers/UsersController.cs index dc270d2..54608ab 100644 --- a/API_SQLuedo/API/Controllers/UsersController.cs +++ b/API_SQLuedo/API/Controllers/UsersController.cs @@ -8,6 +8,7 @@ using Model.Business; using Model.DTO; using Model.Mappers; using Services; +using Utils; namespace API.Controllers { @@ -46,7 +47,7 @@ namespace API.Controllers _logger.LogInformation("[INFORMATION] Utilisateur avec l'id {id} a été trouvé.", id); return Ok(await _dataService.UserService.GetItems(1, 1, UserProperty.Id.ToString(), id)); } - catch (InvalidOperationException) + catch (NoDataFoundException) { _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec l'id {id}.", id); return NotFound(); @@ -61,7 +62,7 @@ namespace API.Controllers _logger.LogInformation("[INFORMATION] Utilisateur avec le username {username} a été trouvé.", username); return Ok(await _dataService.UserService.GetItems(1, 1, UserProperty.Username.ToString(), username)); } - catch (InvalidOperationException) + catch (NoDataFoundException) { _logger.LogError("[ERREUR] Aucun utilisateur trouvé avec le username {username}.", username); return NotFound(); diff --git a/API_SQLuedo/API_SQLuedo.sln b/API_SQLuedo/API_SQLuedo.sln index 0d2bfac..4d8f15d 100644 --- a/API_SQLuedo/API_SQLuedo.sln +++ b/API_SQLuedo/API_SQLuedo.sln @@ -17,9 +17,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DbContextLib", "DbContextLi EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Services", "Services\Services.csproj", "{9BD3DCBA-AFD8-47FA-B07C-613B53E63968}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestConsoleAPI", "TestConsoleAPI\TestConsoleAPI.csproj", "{46376AEF-4093-4AE9-AD2F-F51B541F9C6A}" +EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ModelToEntity", "ModelToEntity\ModelToEntity.csproj", "{8F53CC62-94B3-4F9D-ABF1-F7307A6F27C0}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Shared", "Shared\Shared.csproj", "{B28FD539-6FE4-4B13-9C1F-D88F4771CC69}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Utils", "Utils\Utils.csproj", "{2E7CADAB-30EA-4B9C-922B-EBD08E03686E}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -55,14 +57,18 @@ Global {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Debug|Any CPU.Build.0 = Debug|Any CPU {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Release|Any CPU.ActiveCfg = Release|Any CPU {9BD3DCBA-AFD8-47FA-B07C-613B53E63968}.Release|Any CPU.Build.0 = Release|Any CPU + {46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {46376AEF-4093-4AE9-AD2F-F51B541F9C6A}.Release|Any CPU.Build.0 = Release|Any CPU {8F53CC62-94B3-4F9D-ABF1-F7307A6F27C0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {8F53CC62-94B3-4F9D-ABF1-F7307A6F27C0}.Debug|Any CPU.Build.0 = Debug|Any CPU {8F53CC62-94B3-4F9D-ABF1-F7307A6F27C0}.Release|Any CPU.ActiveCfg = Release|Any CPU {8F53CC62-94B3-4F9D-ABF1-F7307A6F27C0}.Release|Any CPU.Build.0 = Release|Any CPU - {B28FD539-6FE4-4B13-9C1F-D88F4771CC69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {B28FD539-6FE4-4B13-9C1F-D88F4771CC69}.Debug|Any CPU.Build.0 = Debug|Any CPU - {B28FD539-6FE4-4B13-9C1F-D88F4771CC69}.Release|Any CPU.ActiveCfg = Release|Any CPU - {B28FD539-6FE4-4B13-9C1F-D88F4771CC69}.Release|Any CPU.Build.0 = Release|Any CPU + {2E7CADAB-30EA-4B9C-922B-EBD08E03686E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2E7CADAB-30EA-4B9C-922B-EBD08E03686E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2E7CADAB-30EA-4B9C-922B-EBD08E03686E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2E7CADAB-30EA-4B9C-922B-EBD08E03686E}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/API_SQLuedo/Services/Services.csproj b/API_SQLuedo/Services/Services.csproj index 4f252a2..29b1748 100644 --- a/API_SQLuedo/Services/Services.csproj +++ b/API_SQLuedo/Services/Services.csproj @@ -25,6 +25,7 @@ + diff --git a/API_SQLuedo/Services/UserDataService.cs b/API_SQLuedo/Services/UserDataService.cs index 81ba9d4..bb29d27 100644 --- a/API_SQLuedo/Services/UserDataService.cs +++ b/API_SQLuedo/Services/UserDataService.cs @@ -10,6 +10,7 @@ using Model.Business; using Microsoft.EntityFrameworkCore; using Entities.SQLudeoDB; using ModelToEntity; +using Utils; namespace Services { @@ -83,7 +84,7 @@ namespace Services var items = await dataServiceEF.GetItems(page, count, orderingPropertyName, valueProperty); if (items == null) { - throw new InvalidOperationException("aucune donnée trouvé"); + throw new NoDataFoundException(); } return items.Select(item => item.FromModelToDTO()); }