mirror of
https://github.com/C9Glax/tranga.git
synced 2025-06-12 06:27:54 +02:00
MangaConnectors in API
This commit is contained in:
@ -3,6 +3,7 @@ using API.Schema.Jobs;
|
||||
using API.Schema.MangaConnectors;
|
||||
using Asp.Versioning;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Soenneker.Utils.String.NeedlemanWunsch;
|
||||
using static Microsoft.AspNetCore.Http.StatusCodes;
|
||||
|
||||
@ -35,12 +36,26 @@ public class ConnectorController(PgsqlContext context) : Controller
|
||||
[ProducesResponseType<Manga[]>(Status500InternalServerError)]
|
||||
public IActionResult SearchMangaGlobal(string name)
|
||||
{
|
||||
List<Manga> allManga = new List<Manga>();
|
||||
List<(Manga, Author[], MangaTag[], Link[], MangaAltTitle[])> allManga = new();
|
||||
foreach (MangaConnector contextMangaConnector in context.MangaConnectors)
|
||||
{
|
||||
allManga.AddRange(contextMangaConnector.GetManga(name));
|
||||
foreach ((Manga? manga, Author[]? authors, MangaTag[]? tags, Link[]? links, MangaAltTitle[]? altTitles) in allManga)
|
||||
{
|
||||
try
|
||||
{
|
||||
context.Tags.AddRange(tags);
|
||||
context.Authors.AddRange(authors);
|
||||
context.Link.AddRange(links);
|
||||
context.AltTitles.AddRange(altTitles);
|
||||
context.Manga.AddRange(manga);
|
||||
context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
return StatusCode(500, new ProblemResponse("An error occurred while processing your request."));
|
||||
}
|
||||
}
|
||||
return Ok(allManga.ToArray());
|
||||
return Ok(allManga.Select(m => m.Item1).ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -52,12 +67,29 @@ public class ConnectorController(PgsqlContext context) : Controller
|
||||
[HttpPost("{id}/SearchManga")]
|
||||
[ProducesResponseType<Manga[]>(Status200OK)]
|
||||
[ProducesResponseType<ProblemResponse>(Status404NotFound)]
|
||||
[ProducesResponseType<ProblemResponse>(Status500InternalServerError)]
|
||||
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);
|
||||
(Manga, Author[], MangaTag[], Link[], MangaAltTitle[])[] mangas = connector.GetManga(name);
|
||||
foreach ((Manga? manga, Author[]? authors, MangaTag[]? tags, Link[]? links, MangaAltTitle[]? altTitles) in mangas)
|
||||
{
|
||||
try
|
||||
{
|
||||
context.Tags.AddRange(tags);
|
||||
context.Authors.AddRange(authors);
|
||||
context.Link.AddRange(links);
|
||||
context.AltTitles.AddRange(altTitles);
|
||||
context.Manga.AddRange(manga);
|
||||
context.SaveChanges();
|
||||
}
|
||||
catch (DbUpdateException)
|
||||
{
|
||||
return StatusCode(500, new ProblemResponse("An error occurred while processing your request."));
|
||||
}
|
||||
}
|
||||
return Ok(mangas.Select(m => m.Item1).ToArray());
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user