diff --git a/Controllers/ApiController.cs b/Controllers/ApiController.cs index 54a5c03..fcabb81 100644 --- a/Controllers/ApiController.cs +++ b/Controllers/ApiController.cs @@ -3,6 +3,7 @@ using BinaryDad.Notes.Services; namespace BinaryDad.Notes.Controllers { + [ApiController] public class ApiController : ControllerBase { private readonly INoteService noteService; @@ -12,6 +13,7 @@ namespace BinaryDad.Notes.Controllers this.noteService = noteService; } + [Route("note/{noteName}")] public string Note(string noteName) => noteService.GetText(noteName); } } diff --git a/Controllers/NoteController.cs b/Controllers/NoteController.cs index 9f9fe79..839646d 100644 --- a/Controllers/NoteController.cs +++ b/Controllers/NoteController.cs @@ -1,4 +1,4 @@ -using BinaryDad.Notes.Models; +using BinaryDad.Notes.Models; using BinaryDad.Notes.Services; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Mvc; @@ -15,9 +15,14 @@ public class NoteController : Controller this.noteService = noteService; } - [Route("{noteName=default}")] + [Route("{noteName?}")] public IActionResult Index(string noteName) { + if (string.IsNullOrWhiteSpace(noteName)) + { + noteName = "default"; + } + var model = new ContentModel { CurrentNote = noteName, diff --git a/Services/FileNoteService.cs b/Services/FileNoteService.cs index 0b9f035..4c5fed6 100644 --- a/Services/FileNoteService.cs +++ b/Services/FileNoteService.cs @@ -4,9 +4,16 @@ { private readonly string filePath; + private static readonly string defaultFilePath = "notes"; + public FileNoteService(IConfiguration configuration) { - filePath = configuration["FileNoteService:ContentFilePath"].Trim(); + filePath = configuration["FileNoteService:ContentFilePath"]; + + if (string.IsNullOrWhiteSpace(filePath)) + { + filePath = defaultFilePath; + } } public string GetText(string noteName) diff --git a/Views/Note/Index.cshtml b/Views/Note/Index.cshtml index f643373..f2a71f9 100644 --- a/Views/Note/Index.cshtml +++ b/Views/Note/Index.cshtml @@ -12,4 +12,11 @@