diff --git a/API_SQLuedo/API/Controllers/NotepadController.cs b/API_SQLuedo/API/Controllers/NotepadController.cs index df0bb09..1bf74ce 100644 --- a/API_SQLuedo/API/Controllers/NotepadController.cs +++ b/API_SQLuedo/API/Controllers/NotepadController.cs @@ -1,5 +1,6 @@ using Asp.Versioning; using Dto; +using Entities; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; using Shared; @@ -52,6 +53,7 @@ public class NotepadController(ILogger logger, INotePadServic try { var existingNotePad = notePadService.GetNotePadByIdUserAndIdInquiry(notepadDto.UserId, notepadDto.InquiryId); + logger.LogError("[ERREUR] Le bloc note existe déjà impossible de le crée"); return StatusCode(409, existingNotePad); } catch (ArgumentException) @@ -59,4 +61,17 @@ public class NotepadController(ILogger logger, INotePadServic return Ok(notePadService.CreateNotePad(notepadDto.Id, notepadDto.UserId, notepadDto.InquiryId, notepadDto.Notes)); } } + [HttpDelete] + [ProducesResponseType(typeof(UserDto), 200)] + [ProducesResponseType(typeof(string), 404)] + public IActionResult DeleteNotePad(int id) + { + if (notePadService.DeleteNotePad(id)) + { + logger.LogInformation("[INFORMATION] le bloc note avec l'id {id} a été supprimé.", id); + return Ok(); + } + logger.LogError("[ERREUR] Aucun bloc note trouvé avec l'id {id}.", id); + return NotFound(); + } } \ No newline at end of file diff --git a/API_SQLuedo/API/Service/NotePadDataServiceApi.cs b/API_SQLuedo/API/Service/NotePadDataServiceApi.cs index 86dae41..d8a097a 100644 --- a/API_SQLuedo/API/Service/NotePadDataServiceApi.cs +++ b/API_SQLuedo/API/Service/NotePadDataServiceApi.cs @@ -14,4 +14,6 @@ public class NotePadDataServiceApi(INotePadService notePadService public NotepadDto CreateNotePad(int id, int idUser, int idInquiry, string note) => notePadService.CreateNotePad(id, idUser, idInquiry, note).FromEntityToDto(); + + public bool DeleteNotePad(int id) => notePadService.DeleteNotePad(id); } \ No newline at end of file diff --git a/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs b/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs index 49f10e3..425ab8f 100644 --- a/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs +++ b/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs @@ -48,4 +48,17 @@ public class NotePadDataService : INotePadService DbContext.SaveChangesAsync(); return notePadEntity; } + + public bool DeleteNotePad(int id) + { + var notePadEntity = DbContext.Notepads.FirstOrDefault(n => n.Id == id); + if (notePadEntity == null) + { + return false; + } + + DbContext.Notepads.Remove(notePadEntity); + DbContext.SaveChangesAsync(); + return true; + } } \ No newline at end of file diff --git a/API_SQLuedo/Shared/INotePadService.cs b/API_SQLuedo/Shared/INotePadService.cs index 0693a22..a38fed5 100644 --- a/API_SQLuedo/Shared/INotePadService.cs +++ b/API_SQLuedo/Shared/INotePadService.cs @@ -7,5 +7,6 @@ public interface INotePadService public TNotePad GetNotePadById(int id); public TNotePad GetNotePadByIdUserAndIdInquiry(int idUser, int idInquiry); public TNotePad CreateNotePad(int id, int idUser, int idInquiry, string note); + public bool DeleteNotePad(int id); } \ No newline at end of file