ajout de DeleteNotePad
continuous-integration/drone/push Build is passing Details

notePad
Victor GABORIT 1 year ago
parent 0ac95dfae6
commit e6bcf72fd1

@ -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<NotepadController> 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<NotepadController> 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();
}
}

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

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

@ -7,5 +7,6 @@ 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);
public bool DeleteNotePad(int id);
}
Loading…
Cancel
Save