mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 11:58: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.Schema.MangaContext;
|
||||||
using API.Workers;
|
using API.Workers;
|
||||||
using Asp.Versioning;
|
using Asp.Versioning;
|
||||||
@@ -24,16 +25,16 @@ public class MangaController(MangaContext context) : Controller
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all cached <see cref="Manga"/>
|
/// Returns all cached <see cref="Manga"/>
|
||||||
/// </summary>
|
/// </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>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
[ProducesResponseType<MinimalManga[]>(Status200OK, "application/json")]
|
||||||
public async Task<IActionResult> GetAllManga ()
|
public async Task<IActionResult> GetAllManga ()
|
||||||
{
|
{
|
||||||
if(await context.Mangas.ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
if(await context.Mangas.ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
return StatusCode(Status500InternalServerError);
|
return StatusCode(Status500InternalServerError);
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result.Select(m => new MinimalManga(m.Key, m.Name, m.Description, m.ReleaseStatus)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -54,18 +55,19 @@ public class MangaController(MangaContext context) : Controller
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Returns all <see cref="Manga"/> that are being downloaded from at least one <see cref="MangaConnector"/>
|
/// Returns all <see cref="Manga"/> that are being downloaded from at least one <see cref="MangaConnector"/>
|
||||||
/// </summary>
|
/// </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>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpGet("Downloading")]
|
[HttpGet("Downloading")]
|
||||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
[ProducesResponseType<MinimalManga[]>(Status200OK, "application/json")]
|
||||||
public async Task<IActionResult> GetMangaDownloading ()
|
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))
|
.Where(m => m.MangaConnectorIds.Any(id => id.UseForDownload))
|
||||||
.ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
.ToArrayAsync(HttpContext.RequestAborted) is not { } result)
|
||||||
return StatusCode(Status500InternalServerError);
|
return StatusCode(Status500InternalServerError);
|
||||||
|
|
||||||
return Ok(result);
|
return Ok(result.Select(m => new MinimalManga(m.Key, m.Name, m.Description, m.ReleaseStatus)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -76,7 +78,7 @@ public class MangaController(MangaContext context) : Controller
|
|||||||
/// <response code="500">Error during Database Operation</response>
|
/// <response code="500">Error during Database Operation</response>
|
||||||
[HttpPost("WithIDs")]
|
[HttpPost("WithIDs")]
|
||||||
[ProducesResponseType<Manga[]>(Status200OK, "application/json")]
|
[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()
|
if(await context.MangaIncludeAll()
|
||||||
.Where(m => MangaIds.Contains(m.Key))
|
.Where(m => MangaIds.Contains(m.Key))
|
||||||
|
@@ -115,7 +115,9 @@ public class MangaContext(DbContextOptions<MangaContext> options) : TrangaBaseCo
|
|||||||
m.AltTitles.Any(t => other.AltTitles.Select(ot => ot.Title).Any(s => s.Equals(t.Title))), token);
|
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)
|
public IIncludableQueryable<Manga, ICollection<MangaConnectorId<Manga>>> MangaIncludeAll() =>
|
||||||
|
Mangas
|
||||||
|
.Include(m => m.Library)
|
||||||
.Include(m => m.Authors)
|
.Include(m => m.Authors)
|
||||||
.Include(m => m.MangaTags)
|
.Include(m => m.MangaTags)
|
||||||
.Include(m => m.Links)
|
.Include(m => m.Links)
|
||||||
|
Reference in New Issue
Block a user