using Microsoft.AspNetCore.Authorization;using Microsoft.AspNetCore.Mvc;using PlotLine.Services.Context; namespace PlotLine.Controllers; [Authorize,Route("Writing/Context/Relationships"),ResponseCache(NoStore=true,Location=ResponseCacheLocation.None)] public sealed class ContextRelationshipLensesController(ContextRelationshipLenses lenses,ContextFamilyExploration families):Controller { [HttpGet("Graph")] public async Task Graph(int bookId,int sceneId,string lens="family",int? focusId=null,int depth=3,CancellationToken cancellationToken=default) {try{return Ok(await lenses.Graph(bookId,sceneId,lens,focusId,depth,cancellationToken));}catch(UnauthorizedAccessException){return Forbid();}catch(ArgumentException e){return BadRequest(new{message=e.Message});}} [HttpGet("FamilyIndex")] public async Task FamilyIndex(int bookId,int sceneId,CancellationToken cancellationToken) {try{return Ok(await families.Index(bookId,sceneId,cancellationToken));}catch(UnauthorizedAccessException){return Forbid();}catch(ArgumentException e){return BadRequest(new{message=e.Message});}} [HttpGet("FamilyTree")] public async Task FamilyTree(int bookId,int sceneId,int focusId,[FromQuery] int[]? expanded,CancellationToken cancellationToken) {try{return Ok(await families.Tree(bookId,sceneId,focusId,expanded??[],cancellationToken));}catch(UnauthorizedAccessException){return Forbid();}catch(ArgumentException e){return BadRequest(new{message=e.Message});}} [HttpGet("Lookup")] public async Task Lookup(int bookId,int sceneId,string search,CancellationToken cancellationToken) {if(string.IsNullOrWhiteSpace(search)||search.Length>120)return BadRequest();try{return Ok((await lenses.Lookup(bookId,sceneId,search,cancellationToken)).Select(c=>new{id=c.CharacterID,name=c.CharacterName,archived=c.IsArchived}));}catch(UnauthorizedAccessException){return Forbid();}} }