diff --git a/API_SQLuedo/API/Controllers/NotepadController.cs b/API_SQLuedo/API/Controllers/NotepadController.cs index ca0f5be..df0bb09 100644 --- a/API_SQLuedo/API/Controllers/NotepadController.cs +++ b/API_SQLuedo/API/Controllers/NotepadController.cs @@ -44,4 +44,19 @@ public class NotepadController(ILogger logger, INotePadServic return NotFound(); } } + [HttpPost] + [ProducesResponseType(typeof(UserDto), 201)] + [ProducesResponseType(typeof(string), 409)] + public IActionResult CreateNotePad([FromBody] NotepadDto notepadDto) + { + try + { + var existingNotePad = notePadService.GetNotePadByIdUserAndIdInquiry(notepadDto.UserId, notepadDto.InquiryId); + return StatusCode(409, existingNotePad); + } + catch (ArgumentException) + { + return Ok(notePadService.CreateNotePad(notepadDto.Id, notepadDto.UserId, notepadDto.InquiryId, notepadDto.Notes)); + } + } } \ No newline at end of file diff --git a/API_SQLuedo/API/Service/NotePadDataServiceApi.cs b/API_SQLuedo/API/Service/NotePadDataServiceApi.cs index 1eca632..86dae41 100644 --- a/API_SQLuedo/API/Service/NotePadDataServiceApi.cs +++ b/API_SQLuedo/API/Service/NotePadDataServiceApi.cs @@ -11,4 +11,7 @@ public class NotePadDataServiceApi(INotePadService notePadService public NotepadDto GetNotePadByIdUserAndIdInquiry(int idUser, int idInquiry) => notePadService.GetNotePadByIdUserAndIdInquiry(idUser, idInquiry).FromEntityToDto(); + + public NotepadDto CreateNotePad(int id, int idUser, int idInquiry, string note) => + notePadService.CreateNotePad(id, idUser, idInquiry, note).FromEntityToDto(); } \ No newline at end of file diff --git a/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs b/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs index 437fa66..49f10e3 100644 --- a/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs +++ b/API_SQLuedo/DbDataManager/Service/NotePadDataService.cs @@ -34,4 +34,18 @@ public class NotePadDataService : INotePadService return notPadEntity; } + + public NotepadEntity CreateNotePad(int id, int idUser, int idInquiry, string note) + { + var notePadEntity = new NotepadEntity + { + Id = id, + UserId = idUser, + InquiryId = idInquiry, + Notes = note + }; + DbContext.Notepads.Add(notePadEntity); + DbContext.SaveChangesAsync(); + return notePadEntity; + } } \ No newline at end of file diff --git a/API_SQLuedo/Shared/INotePadService.cs b/API_SQLuedo/Shared/INotePadService.cs index 4a3adcc..0693a22 100644 --- a/API_SQLuedo/Shared/INotePadService.cs +++ b/API_SQLuedo/Shared/INotePadService.cs @@ -1,8 +1,11 @@ +using Dto; + namespace Shared; 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); } \ No newline at end of file