37 lines
1.7 KiB
C#
37 lines
1.7 KiB
C#
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.Data.SqlClient;
|
|
using PlotLine.Services;
|
|
using PlotLine.Services.Context;
|
|
namespace PlotLine.Controllers;
|
|
|
|
[Authorize, ResponseCache(NoStore = true, Location = ResponseCacheLocation.None)]
|
|
public sealed class ContextWarningsController(ContextWarnings warnings, ContextSpatial spatial,
|
|
IContinuityValidationService validation, ContextWorkspaceNotifications notifications, ICurrentUserService user) : Controller
|
|
{
|
|
[HttpGet]
|
|
public async Task<IActionResult> State(int bookId, int sceneId)
|
|
{
|
|
if (!ModelState.IsValid || bookId <= 0 || sceneId <= 0) return BadRequest();
|
|
try { return Json(await warnings.Read(bookId, sceneId)); }
|
|
catch (SqlException e) when (e.Number == 51010) { return Forbid(); }
|
|
}
|
|
|
|
[HttpPost, ValidateAntiForgeryToken]
|
|
public async Task<IActionResult> Intentional(int bookId, int sceneId, int warningId)
|
|
{
|
|
if (!ModelState.IsValid || bookId <= 0 || sceneId <= 0 || warningId <= 0) return BadRequest();
|
|
try
|
|
{
|
|
var scope = await spatial.Scope(bookId, sceneId);
|
|
if (!scope.CanEdit) return Forbid();
|
|
var frame = await warnings.Read(bookId, sceneId);
|
|
if (!frame.Scenes.Any(s => s.SceneID == sceneId && s.Findings.Any(w => w.ContinuityWarningID == warningId))) return NotFound();
|
|
await validation.MarkIntentionalAsync(warningId);
|
|
await notifications.Invalidate(user.UserId!.Value, projectId: scope.ProjectID, bookId: bookId, kind: "warnings");
|
|
return Json(new { saved = true });
|
|
}
|
|
catch (SqlException e) when (e.Number == 51010) { return Forbid(); }
|
|
}
|
|
}
|