ajout de la methode CreateNotePad
continuous-integration/drone/push Build is passing Details

notePad
Victor GABORIT 1 year ago
parent a1ea2de7bb
commit 0ac95dfae6

@ -44,4 +44,19 @@ public class NotepadController(ILogger<NotepadController> 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));
}
}
}

@ -11,4 +11,7 @@ public class NotePadDataServiceApi(INotePadService<NotepadEntity> 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();
}

@ -34,4 +34,18 @@ public class NotePadDataService : INotePadService<NotepadEntity>
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;
}
}

@ -1,8 +1,11 @@
using Dto;
namespace Shared;
public interface INotePadService<TNotePad>
{
public TNotePad GetNotePadById(int id);
public TNotePad GetNotePadByIdUserAndIdInquiry(int idUser, int idInquiry);
public TNotePad CreateNotePad(int id, int idUser, int idInquiry, string note);
}
Loading…
Cancel
Save