From faaa0dba8f210b0825a896376454262736c2e5a3 Mon Sep 17 00:00:00 2001 From: Ryan Date: Fri, 12 May 2023 12:47:54 -0400 Subject: [PATCH] add delete endpoint --- Controllers/HomeController.cs | 8 ++++++++ Services/FileNoteService.cs | 7 +++++++ Services/INoteService.cs | 1 + 3 files changed, 16 insertions(+) diff --git a/Controllers/HomeController.cs b/Controllers/HomeController.cs index 8841348..02fc0c4 100644 --- a/Controllers/HomeController.cs +++ b/Controllers/HomeController.cs @@ -24,4 +24,12 @@ public class HomeController : Controller return View(model); } + + [Route("{noteName}/delete")] + public IActionResult Delete(string noteName) + { + noteService.DeleteNote(noteName); + + return Redirect("/"); + } } diff --git a/Services/FileNoteService.cs b/Services/FileNoteService.cs index 6d1eed5..93c7297 100644 --- a/Services/FileNoteService.cs +++ b/Services/FileNoteService.cs @@ -32,6 +32,13 @@ File.WriteAllText(GetFilePath(noteName), content); } + public void DeleteNote(string noteName) + { + var filePath = GetFilePath(noteName); + + File.Delete(filePath); + } + private void CheckFile(string noteName) { var filePath = GetFilePath(noteName); diff --git a/Services/INoteService.cs b/Services/INoteService.cs index a5467b2..7d9ff99 100644 --- a/Services/INoteService.cs +++ b/Services/INoteService.cs @@ -5,5 +5,6 @@ ICollection GetNoteNames(); string GetText(string? noteName); void SaveText(string content, string? noteName); + void DeleteNote(string noteName); } }