PlotDirector/PlotLine/Controllers/ContextIntentController.cs
2026-12-02 21:05:56 +00:00

25 lines
1005 B
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Data.SqlClient;
using PlotLine.Services.Context;
namespace PlotLine.Controllers;
[Authorize]
[Route("Writing/Context/Intent")]
[ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
public sealed class ContextIntentController(ContextIntentPalette palette) : Controller
{
// Reusable read endpoint for both Context and the docked Writer component.
// It takes an explicit held scope and never follows or changes the Word caret.
[HttpGet("Palette")]
public async Task<IActionResult> Palette([FromQuery] IntentPaletteQuery query)
{
if (!ModelState.IsValid) return BadRequest();
try { return Json(await palette.Read(query)); }
catch (ArgumentException e) { return BadRequest(new { message = e.Message }); }
catch (UnauthorizedAccessException) { return Forbid(); }
catch (SqlException e) when (e.Number == 51010) { return Forbid(); }
}
}