mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 03:48:19 +02:00
Return new DTO "MinimalManga" for endpoints that return a lot of Manga-data
This commit is contained in:
5
API/Controllers/DTOs/MinimalManga.cs
Normal file
5
API/Controllers/DTOs/MinimalManga.cs
Normal file
@@ -0,0 +1,5 @@
|
||||
using API.Schema.MangaContext;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
public sealed record MinimalManga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus);
|
@@ -1,4 +1,5 @@
|
||||
using API.MangaConnectors;
|
||||
using API.Controllers.DTOs;
|
||||
using API.MangaConnectors;
|
||||
using API.Schema.MangaContext;
|
||||
using API.Workers;
|
||||
using Asp.Versioning;
|
||||
@@ -24,16 +25,16 @@ public class MangaController(MangaContext context) : Controller
|
||||
/// <summary>
|
||||
/// Returns all cached <see cref="Manga"/>
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="200"><see cref="MinimalManga"/> exert of <see cref="Manga"/>. Use <see cref="GetManga"/> for more information</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpGet]
|
||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
||||
[ProducesResponseType<MinimalManga[]>(Status200OK, "application/json")]
|
||||
public async Task<IActionResult> GetAllManga ()
|
||||
{
|
||||
if(await context.Mangas.ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
||||
return StatusCode(Status500InternalServerError);
|
||||
|
||||
return Ok(result);
|
||||
return Ok(result.Select(m => new MinimalManga(m.Key, m.Name, m.Description, m.ReleaseStatus)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -54,18 +55,19 @@ public class MangaController(MangaContext context) : Controller
|
||||
/// <summary>
|
||||
/// Returns all <see cref="Manga"/> that are being downloaded from at least one <see cref="MangaConnector"/>
|
||||
/// </summary>
|
||||
/// <response code="200"></response>
|
||||
/// <response code="200"><see cref="MinimalManga"/> exert of <see cref="Manga"/>. Use <see cref="GetManga"/> for more information</response>
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpGet("Downloading")]
|
||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
||||
[ProducesResponseType<MinimalManga[]>(Status200OK, "application/json")]
|
||||
public async Task<IActionResult> GetMangaDownloading ()
|
||||
{
|
||||
if(await context.MangaIncludeAll()
|
||||
if(await context.Mangas
|
||||
.Include(m => m.MangaConnectorIds)
|
||||
.Where(m => m.MangaConnectorIds.Any(id => id.UseForDownload))
|
||||
.ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
||||
return StatusCode(Status500InternalServerError);
|
||||
|
||||
return Ok(result);
|
||||
return Ok(result.Select(m => new MinimalManga(m.Key, m.Name, m.Description, m.ReleaseStatus)));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -76,7 +78,7 @@ public class MangaController(MangaContext context) : Controller
|
||||
/// <response code="500">Error during Database Operation</response>
|
||||
[HttpPost("WithIDs")]
|
||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
||||
public async Task<IActionResult> GetManga ([FromBody]string[] MangaIds)
|
||||
public async Task<IActionResult> GetMangaWithIds ([FromBody]string[] MangaIds)
|
||||
{
|
||||
if(await context.MangaIncludeAll()
|
||||
.Where(m => MangaIds.Contains(m.Key))
|
||||
|
@@ -115,11 +115,13 @@ public class MangaContext(DbContextOptions<MangaContext> options) : TrangaBaseCo
|
||||
m.AltTitles.Any(t => other.AltTitles.Select(ot => ot.Title).Any(s => s.Equals(t.Title))), token);
|
||||
}
|
||||
|
||||
public IIncludableQueryable<Manga, ICollection<MangaConnectorId<Manga>>> MangaIncludeAll() => Mangas.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);
|
||||
public IIncludableQueryable<Manga, ICollection<MangaConnectorId<Manga>>> MangaIncludeAll() =>
|
||||
Mangas
|
||||
.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);
|
||||
}
|
Reference in New Issue
Block a user