diff --git a/API/Controllers/QueryController.cs b/API/Controllers/QueryController.cs index e3062b0..b8c692d 100644 --- a/API/Controllers/QueryController.cs +++ b/API/Controllers/QueryController.cs @@ -2,7 +2,7 @@ using API.Schema.MangaContext; using Asp.Versioning; using Microsoft.AspNetCore.Mvc; -using Microsoft.EntityFrameworkCore; +using Soenneker.Utils.String.NeedlemanWunsch; using static Microsoft.AspNetCore.Http.StatusCodes; // ReSharper disable InconsistentNaming @@ -72,18 +72,33 @@ public class QueryController(MangaContext context) : Controller [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) + Manga[] ret = context.MangaIncludeAll() + .Where(m => m.MangaConnectorIds.Any(id => id.UseForDownload)) .ToArray(); return Ok(ret); } + /// + /// Returns with names similar to (identified by + /// + /// Key of + /// + /// with not found + [HttpGet("Manga/{MangaId}/SimilarName")] + [ProducesResponseType(Status200OK, "application/json")] + [ProducesResponseType(Status404NotFound)] + public IActionResult GetSimilarManga(string MangaId) + { + if (context.Mangas.Find(MangaId) is not { } manga) + return NotFound(); + string name = manga.Name; + Dictionary mangaNames = context.Mangas.Where(m => m.Key != MangaId).ToDictionary(m => m.Key, m => m.Name); + string[] similarIds = mangaNames + .Where(kv => NeedlemanWunschStringUtil.CalculateSimilarityPercentage(name, kv.Value) > 0.8) + .Select(kv => kv.Key).ToArray(); + return Ok(similarIds); + } + /// /// Returns the with .Key ///