Restructuing

This commit is contained in:
2026-07-05 16:30:58 -04:00
parent 678e20d402
commit 7b0f2ce1a5
767 changed files with 354 additions and 76 deletions
@@ -0,0 +1,55 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Model;
namespace Cloud.Controllers;
[Authorize]
[ApiController]
[Route("api/[controller]")]
public class NotesController : ControllerBase
{
private readonly AppDbContext _context;
public NotesController(AppDbContext context)
{
_context = context;
}
[HttpGet("{cardName}")]
public async Task<ActionResult<CardNote>> GetNote(string cardName)
{
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 = "" });
}
}
[HttpPost]
public async Task<ActionResult<CardNote>> UpdateNote(CardNote note)
{
try
{
var existing = await _context.CardNotes.FindAsync(note.CardName);
if (existing == null)
_context.CardNotes.Add(note);
else
existing.Note = note.Note;
await _context.SaveChangesAsync();
}
catch (Exception ex)
{
Console.WriteLine($"[WARNING] Could not save note to database: {ex.Message}");
}
return Ok(note);
}
}