using API.Schema;
using API.Schema.Jobs;
using API.Schema.MangaConnectors;
using Asp.Versioning;
using Microsoft.AspNetCore.Mvc;
using Soenneker.Utils.String.NeedlemanWunsch;
using static Microsoft.AspNetCore.Http.StatusCodes;
namespace API.Controllers;
[ApiVersion(2)]
[ApiController]
[Produces("application/json")]
[Route("v{v:apiVersion}/[controller]")]
public class ConnectorController(PgsqlContext context) : Controller
{
///
/// Get all available Connectors (Scanlation-Sites)
///
/// Array of MangaConnector
[HttpGet]
[ProducesResponseType(Status200OK)]
public IActionResult GetConnectors()
{
MangaConnector[] connectors = context.MangaConnectors.ToArray();
return Ok(connectors);
}
///
/// Initiate a search for a Manga on all Connectors
///
/// Name/Title of the Manga
/// Array of Manga
[HttpPost("SearchManga")]
[ProducesResponseType(Status500InternalServerError)]
public IActionResult SearchMangaGlobal(string name)
{
List allManga = new List();
foreach (MangaConnector contextMangaConnector in context.MangaConnectors)
{
allManga.AddRange(contextMangaConnector.GetManga(name));
}
return Ok(allManga.ToArray());
}
///
/// Initiate a search for a Manga on a specific Connector
///
/// Manga-Connector-ID
/// Name/Title of the Manga
/// Manga
[HttpPost("{id}/SearchManga")]
[ProducesResponseType(Status200OK)]
[ProducesResponseType(Status404NotFound)]
public IActionResult SearchManga(string id, [FromBody]string name)
{
MangaConnector? connector = context.MangaConnectors.Find(id);
if (connector is null)
return NotFound(new ProblemResponse("Connector not found."));
Manga[] manga = connector.GetManga(name);
return Ok(manga);
}
}