Server now silently fails with no PostgreSQL
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user