using API.Controllers.DTOs; using API.Schema.MangaContext; using Asp.Versioning; using Microsoft.AspNetCore.Http.HttpResults; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Soenneker.Utils.String.NeedlemanWunsch; using static Microsoft.AspNetCore.Http.StatusCodes; using Author = API.Controllers.DTOs.Author; using Chapter = API.Controllers.DTOs.Chapter; // ReSharper disable InconsistentNaming namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/")] public class QueryController(MangaContext context) : Controller { /// /// Returns the with /// /// .Key /// /// with not found [HttpGet("Author/{AuthorId}")] [ProducesResponseType(Status200OK, "application/json")] [ProducesResponseType(Status404NotFound, "text/plain")] public async Task, NotFound>> GetAuthor (string AuthorId) { if (await context.Authors.FirstOrDefaultAsync(a => a.Key == AuthorId, HttpContext.RequestAborted) is not { } author) return TypedResults.NotFound(nameof(AuthorId)); return TypedResults.Ok(new Author(author.Key, author.AuthorName)); } }