diff --git a/API/Controllers/DTOs/MinimalManga.cs b/API/Controllers/DTOs/MinimalManga.cs new file mode 100644 index 0000000..4d75fc1 --- /dev/null +++ b/API/Controllers/DTOs/MinimalManga.cs @@ -0,0 +1,5 @@ +using API.Schema.MangaContext; + +namespace API.Controllers.DTOs; + +public sealed record MinimalManga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus); \ No newline at end of file diff --git a/API/Controllers/MangaController.cs b/API/Controllers/MangaController.cs index 5f0d222..6381244 100644 --- a/API/Controllers/MangaController.cs +++ b/API/Controllers/MangaController.cs @@ -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 /// /// Returns all cached /// - /// + /// exert of . Use for more information /// Error during Database Operation [HttpGet] - [ProducesResponseType(Status200OK, "application/json")] + [ProducesResponseType(Status200OK, "application/json")] public async Task 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))); } /// @@ -54,18 +55,19 @@ public class MangaController(MangaContext context) : Controller /// /// Returns all that are being downloaded from at least one /// - /// + /// exert of . Use for more information /// Error during Database Operation [HttpGet("Downloading")] - [ProducesResponseType(Status200OK, "application/json")] + [ProducesResponseType(Status200OK, "application/json")] public async Task 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))); } /// @@ -76,7 +78,7 @@ public class MangaController(MangaContext context) : Controller /// Error during Database Operation [HttpPost("WithIDs")] [ProducesResponseType(Status200OK, "application/json")] - public async Task GetManga ([FromBody]string[] MangaIds) + public async Task GetMangaWithIds ([FromBody]string[] MangaIds) { if(await context.MangaIncludeAll() .Where(m => MangaIds.Contains(m.Key)) diff --git a/API/Schema/MangaContext/MangaContext.cs b/API/Schema/MangaContext/MangaContext.cs index 38a0f5c..080ff5a 100644 --- a/API/Schema/MangaContext/MangaContext.cs +++ b/API/Schema/MangaContext/MangaContext.cs @@ -115,11 +115,13 @@ public class MangaContext(DbContextOptions options) : TrangaBaseCo m.AltTitles.Any(t => other.AltTitles.Select(ot => ot.Title).Any(s => s.Equals(t.Title))), token); } - public IIncludableQueryable>> 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>> 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); } \ No newline at end of file