change folder path naming

This commit is contained in:
Ryan Peters 2024-01-06 21:01:17 -05:00
parent ac13770ce0
commit 8b04e4efd2
2 changed files with 10 additions and 8 deletions

View File

@ -2,17 +2,17 @@
{ {
public class FileNoteService : INoteService 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) 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<string> GetNoteNames() public ICollection<string> GetNoteNames()
{ {
return Directory.GetFiles(filePath) return Directory.GetFiles(folderPath)
.Select(f => Path.GetFileName(f)) .Select(f => Path.GetFileName(f))
.ToList(); .ToList();
} }
@ -49,6 +49,8 @@
// ensure initialized // ensure initialized
if (!File.Exists(filePath)) 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); 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(); noteName = noteName.Trim().ToLower();
return Path.Combine(filePath, noteName); return Path.Combine(folderPath, noteName);
} }
} }
} }

View File

@ -7,6 +7,6 @@
}, },
"AllowedHosts": "*", "AllowedHosts": "*",
"FileNoteService": { "FileNoteService": {
"ContentFilePath": "notes" "ContentFolder": "notes"
} }
} }