using API.Schema.MangaContext;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
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 all which where Authored by with
///
/// .Key
///
/// with
[HttpGet("Mangas/WithAuthorId/{AuthorId}")]
[ProducesResponseType(Status200OK, "application/json")]
public IActionResult GetMangaWithAuthorIds(string AuthorId)
{
if (context.Authors.Find(AuthorId) is not { } author)
return NotFound();
return Ok(context.Mangas.Where(m => m.Authors.Contains(author)));
}
///
/// Returns all with
///
/// .Tag
///
/// not found
[HttpGet("Mangas/WithTag/{Tag}")]
[ProducesResponseType(Status200OK, "application/json")]
public IActionResult GetMangasWithTag(string Tag)
{
if (context.Tags.Find(Tag) is not { } tag)
return NotFound();
return Ok(context.Mangas.Where(m => m.MangaTags.Contains(tag)));
}
///
/// Returns with
///
/// .Key
///
/// with not found
[HttpGet("Chapter/{ChapterId}")]
[ProducesResponseType(Status200OK, "application/json")]
public IActionResult GetChapter(string ChapterId)
{
if (context.Chapters.Find(ChapterId) is not { } chapter)
return NotFound();
return Ok(chapter);
}
}