working nicely

This commit is contained in:
Ryan Peters
2023-05-17 21:44:41 -04:00
parent 8e7b9c9622
commit 400f20e916
10 changed files with 44 additions and 37 deletions

View File

@ -2,18 +2,14 @@
{
public class FileNoteService : INoteService
{
private readonly string defaultFileName;
private readonly string filePath;
public FileNoteService(IConfiguration configuration)
{
defaultFileName = configuration["DefaultContentFileName"].Trim().ToLower();
filePath = configuration["ContentFilePath"].Trim();
CheckFile(defaultFileName);
filePath = configuration["FileNoteService:ContentFilePath"].Trim();
}
public string GetText(string? noteName)
public string GetText(string noteName)
{
CheckFile(noteName);
@ -27,7 +23,7 @@
.ToList();
}
public void SaveText(string content, string? noteName)
public void SaveText(string content, string noteName)
{
File.WriteAllText(GetFilePath(noteName), content);
}
@ -39,7 +35,7 @@
File.Delete(filePath);
}
private void CheckFile(string? noteName)
private void CheckFile(string noteName)
{
var filePath = GetFilePath(noteName);
@ -50,10 +46,8 @@
}
}
private string GetFilePath(string? noteName)
private string GetFilePath(string noteName)
{
noteName = string.IsNullOrWhiteSpace(noteName) ? defaultFileName : noteName;
noteName = noteName.Trim().ToLower();
return Path.Combine(filePath, noteName);

View File

@ -3,8 +3,8 @@
public interface INoteService
{
ICollection<string> GetNoteNames();
string GetText(string? noteName);
void SaveText(string content, string? noteName);
string GetText(string noteName);
void SaveText(string content, string noteName);
void DeleteNote(string noteName);
}
}