Server now silently fails with no PostgreSQL

This commit is contained in:
2026-06-18 18:47:42 -04:00
parent 6a2a8abb22
commit 3904e0bce5
4 changed files with 48 additions and 16 deletions
+28 -12
View File
@@ -18,28 +18,44 @@ public class NotesController : ControllerBase
[HttpGet("{cardName}")]
public async Task<ActionResult<CardNote>> GetNote(string cardName)
{
var note = await _context.CardNotes.FindAsync(cardName);
if (note == null)
try
{
var note = await _context.CardNotes.FindAsync(cardName);
if (note == null)
{
return Ok(new CardNote { CardName = cardName, Note = "" });
}
return Ok(note);
}
catch (Exception ex)
{
Console.WriteLine($"[WARNING] Could not retrieve note from database: {ex.Message}");
return Ok(new CardNote { CardName = cardName, Note = "" });
}
return Ok(note);
}
[HttpPost]
public async Task<ActionResult<CardNote>> UpdateNote(CardNote note)
{
var existing = await _context.CardNotes.FindAsync(note.CardName);
if (existing == null)
try
{
_context.CardNotes.Add(note);
}
else
{
existing.Note = note.Note;
}
var existing = await _context.CardNotes.FindAsync(note.CardName);
if (existing == null)
{
_context.CardNotes.Add(note);
}
else
{
existing.Note = note.Note;
}
await _context.SaveChangesAsync();
await _context.SaveChangesAsync();
}
catch (Exception ex)
{
Console.WriteLine($"[WARNING] Could not save note to database: {ex.Message}");
}
return Ok(note);
}
}