From a1ea2de7bbd9ff62dd5b4e5afe1cc46e9e4e4d30 Mon Sep 17 00:00:00 2001 From: Victor GABORIT Date: Sun, 31 Mar 2024 10:14:24 +0200 Subject: [PATCH] ajout de la methode getNotePadByIdUserAndIdInquiry --- .../API/Controllers/NotepadController.cs | 18 +++++++++++++++++- .../API/Service/NotePadDataServiceApi.cs | 3 +++ .../Service/NotePadDataService.cs | 11 +++++++++++ API_SQLuedo/Shared/INotePadService.cs | 1 + 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/API_SQLuedo/API/Controllers/NotepadController.cs b/API_SQLuedo/API/Controllers/NotepadController.cs index d174849..ca0f5be 100644 --- a/API_SQLuedo/API/Controllers/NotepadController.cs +++ b/API_SQLuedo/API/Controllers/NotepadController.cs @@ -24,7 +24,23 @@ public class NotepadController(ILogger logger, INotePadServic } catch (ArgumentException) { - logger.LogError("[ERREUR] Aucun bloc n'a été trouvé pour l'id {id}", id); + logger.LogError("[ERREUR] Aucun bloc n'a été trouvé pour l'id {id}.", id); + return NotFound(); + } + } + [HttpGet("notePad/{idUser:int}/{idInquiry:int}")] + [ProducesResponseType(typeof(UserDto), 200)] + [ProducesResponseType(typeof(string), 404)] + public IActionResult GetNotePadByIdInquiryAndIdUser(int idUser, int idInquiry) + { + try + { + logger.LogInformation(" [INFORMATION] Le bloc note a été trouvé."); + return Ok(notePadService.GetNotePadByIdUserAndIdInquiry(idUser, idInquiry)); + } + catch (ArgumentException) + { + logger.LogError("[ERREUR] Aucun bloc n'a été trouvé."); return NotFound(); } } diff --git a/API_SQLuedo/API/Service/NotePadDataServiceApi.cs b/API_SQLuedo/API/Service/NotePadDataServiceApi.cs index c09b35b..1eca632 100644 --- a/API_SQLuedo/API/Service/NotePadDataServiceApi.cs +++ b/API_SQLuedo/API/Service/NotePadDataServiceApi.cs @@ -8,4 +8,7 @@ namespace API.Service; public class NotePadDataServiceApi(INotePadService notePadService) : INotePadService { public NotepadDto GetNotePadById(int id) => notePadService.GetNotePadById(id).FromEntityToDto(); + + public NotepadDto GetNotePadByIdUserAndIdInquiry(int idUser, int idInquiry) => + notePadService.GetNotePadByIdUserAndIdInquiry(idUser, idInquiry).FromEntityToDto(); } \ No newline at end of file diff --git a/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs b/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs index b7a5fc8..437fa66 100644 --- a/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs +++ b/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs @@ -23,4 +23,15 @@ public class NotePadDataService : INotePadService } return notePadEntity; } + + public NotepadEntity GetNotePadByIdUserAndIdInquiry(int idUser, int idInquiry) + { + var notPadEntity = DbContext.Notepads.FirstOrDefault(n => n.InquiryId == idInquiry && n.UserId == idUser); + if (notPadEntity == null) + { + throw new ArgumentException("impossible de trouver le bloc note", nameof(idInquiry)); + } + + return notPadEntity; + } } \ No newline at end of file diff --git a/API_SQLuedo/Shared/INotePadService.cs b/API_SQLuedo/Shared/INotePadService.cs index c941edf..4a3adcc 100644 --- a/API_SQLuedo/Shared/INotePadService.cs +++ b/API_SQLuedo/Shared/INotePadService.cs @@ -3,5 +3,6 @@ namespace Shared; public interface INotePadService { public TNotePad GetNotePadById(int id); + public TNotePad GetNotePadByIdUserAndIdInquiry(int idUser, int idInquiry); } \ No newline at end of file