using API.Schema; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using static Microsoft.AspNetCore.Http.StatusCodes; namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] public class QueryController(PgsqlContext context) : Controller { /// /// Returns the Author-Information for Author-ID /// /// Author-Id /// /// Author with ID not found [HttpGet("Author/{AuthorId}")] [ProducesResponseType(Status200OK, "application/json")] [ProducesResponseType(Status404NotFound)] public IActionResult GetAuthor(string AuthorId) { Author? ret = context.Authors.Find(AuthorId); if (ret is null) return NotFound(); return Ok(ret); } /// /// Returns all Mangas which where Authored by Author with AuthorId /// /// Author-ID /// [HttpGet("Mangas/WithAuthorId/{AuthorId}")] [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetMangaWithAuthorIds(string AuthorId) { return Ok(context.Mangas.Where(m => m.AuthorIds.Contains(AuthorId))); } /// /// Returns Link-Information for Link-Id /// /// /// /// Link with ID not found [HttpGet("Link/{LinkId}")] [ProducesResponseType(Status200OK, "application/json")] [ProducesResponseType(Status404NotFound)] public IActionResult GetLink(string LinkId) { Link? ret = context.Links.Find(LinkId); if (ret is null) return NotFound(); return Ok(ret); } /// /// Returns AltTitle-Information for AltTitle-Id /// /// /// /// AltTitle with ID not found [HttpGet("AltTitle/{AltTitleId}")] [ProducesResponseType(Status200OK, "application/json")] [ProducesResponseType(Status404NotFound)] public IActionResult GetAltTitle(string AltTitleId) { MangaAltTitle? ret = context.AltTitles.Find(AltTitleId); if (ret is null) return NotFound(); return Ok(ret); } /// /// Returns all Manga with Tag /// /// /// [HttpGet("Mangas/WithTag/{Tag}")] [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetMangasWithTag(string Tag) { return Ok(context.Mangas.Where(m => m.Tags.Contains(Tag))); } /// /// Returns Chapter-Information for Chapter-Id /// /// /// /// Chapter with ID not found [HttpGet("Chapter/{ChapterId}")] [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetChapter(string ChapterId) { Chapter? ret = context.Chapters.Find(ChapterId); if (ret is null) return NotFound(); return Ok(ret); } }