using API.MangaConnectors; using API.Schema.MangaContext; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using static Microsoft.AspNetCore.Http.StatusCodes; // ReSharper disable InconsistentNaming namespace API.Controllers; [ApiVersion(2)] [ApiController] [Route("v{v:apiVersion}/[controller]")] public class QueryController(MangaContext context) : Controller { /// /// Returns the with /// /// .Key /// /// with not found [HttpGet("Author/{AuthorId}")] [ProducesResponseType(Status200OK, "application/json")] [ProducesResponseType(Status404NotFound)] public IActionResult GetAuthor(string AuthorId) { if (context.Authors.Find(AuthorId) is not { } author) return NotFound(); return Ok(author); } /// /// Returns with /// /// .Key /// /// with not found [HttpGet("Chapter/{ChapterId}")] [ProducesResponseType(Status200OK, "application/json")] [ProducesResponseType(Status404NotFound)] public IActionResult GetChapter(string ChapterId) { if (context.Chapters.Find(ChapterId) is not { } chapter) return NotFound(); return Ok(chapter); } /// /// Returns the with .Key /// /// Key of /// /// with not found [HttpGet("Manga/MangaConnectorId/{MangaConnectorIdId}")] [ProducesResponseType>(Status200OK, "application/json")] [ProducesResponseType(Status404NotFound)] public IActionResult GetMangaMangaConnectorId(string MangaConnectorIdId) { if(context.MangaConnectorToManga.Find(MangaConnectorIdId) is not { } mcIdManga) return NotFound(); return Ok(mcIdManga); } /// /// Returns all that are being downloaded from at least one /// /// [HttpGet("Manga/Downloading")] [ProducesResponseType(Status200OK, "application/json")] public IActionResult GetMangaDownloading() { Manga[] ret = context.Mangas.Where(m => m.MangaConnectorIds.Any(id => id.UseForDownload)) .Include(m => m.Library) .Include(m => m.Authors) .Include(m => m.MangaTags) .Include(m => m.Links) .Include(m => m.AltTitles) .Include(m => m.Chapters) .Include(m => m.MangaConnectorIds) .ToArray(); return Ok(ret); } /// /// Returns the with .Key /// /// Key of /// /// with not found [HttpGet("Chapter/MangaConnectorId/{MangaConnectorIdId}")] [ProducesResponseType>(Status200OK, "application/json")] [ProducesResponseType(Status404NotFound)] public IActionResult GetChapterMangaConnectorId(string MangaConnectorIdId) { if(context.MangaConnectorToChapter.Find(MangaConnectorIdId) is not { } mcIdChapter) return NotFound(); return Ok(mcIdChapter); } }