diff --git a/Services/FileNoteService.cs b/Services/FileNoteService.cs index 4c5fed6..cc8ffb2 100644 --- a/Services/FileNoteService.cs +++ b/Services/FileNoteService.cs @@ -2,17 +2,17 @@ { public class FileNoteService : INoteService { - private readonly string filePath; + private readonly string folderPath; - private static readonly string defaultFilePath = "notes"; + private static readonly string defaultFolderPath = "notes"; public FileNoteService(IConfiguration configuration) { - filePath = configuration["FileNoteService:ContentFilePath"]; + folderPath = configuration["FileNoteService:ContentFolder"]; - if (string.IsNullOrWhiteSpace(filePath)) + if (string.IsNullOrWhiteSpace(folderPath)) { - filePath = defaultFilePath; + folderPath = defaultFolderPath; } } @@ -25,7 +25,7 @@ public ICollection GetNoteNames() { - return Directory.GetFiles(filePath) + return Directory.GetFiles(folderPath) .Select(f => Path.GetFileName(f)) .ToList(); } @@ -49,6 +49,8 @@ // ensure initialized if (!File.Exists(filePath)) { + Directory.CreateDirectory(folderPath); + SaveText("Hi! Feel free to start typing. Everything will be saved soon after you are done typing.", noteName); } } @@ -57,7 +59,7 @@ { noteName = noteName.Trim().ToLower(); - return Path.Combine(filePath, noteName); + return Path.Combine(folderPath, noteName); } } } diff --git a/appsettings.json b/appsettings.json index 17bfc41..abd5538 100644 --- a/appsettings.json +++ b/appsettings.json @@ -7,6 +7,6 @@ }, "AllowedHosts": "*", "FileNoteService": { - "ContentFilePath": "notes" + "ContentFolder": "notes" } }