17 lines
664 B
C#

using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using PlotLine.Services;
namespace PlotLine.Controllers;
[Authorize,ResponseCache(NoStore=true,Location=ResponseCacheLocation.None)]
public sealed class AiController(IDiscretionaryAi allowance,ICurrentUserService user):Controller
{
[HttpGet]
public async Task<IActionResult> Quote(string operation)
{
if(user.UserId is not int author)return Forbid();
if(string.IsNullOrWhiteSpace(operation)||operation.Length>80)return BadRequest();
var quote=await allowance.Quote(author,operation);
return Json(AiQuotePresentation.From(quote,Url.Action("Subscription","ManageAccount")!));
}
}