From 043f0b9593d1553e3e1ce18cd6a3b7f7945c4d3a Mon Sep 17 00:00:00 2001 From: Glax Date: Fri, 7 Mar 2025 16:37:32 +0100 Subject: [PATCH] #74 Endpoints for latest chapter downloaded and latest chapter available --- API/Controllers/MangaController.cs | 34 ++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/API/Controllers/MangaController.cs b/API/Controllers/MangaController.cs index 2b205cd..a3c930c 100644 --- a/API/Controllers/MangaController.cs +++ b/API/Controllers/MangaController.cs @@ -147,14 +147,14 @@ public class MangaController(PgsqlContext context) : Controller } /// - /// Returns the latest Chapter of requested Manga + /// Returns the latest Chapter of requested Manga available on Website /// /// Manga-ID /// /// No available chapters /// Manga with ID not found. /// Could not retrieve the maximum chapter-number - [HttpGet("{id}/Chapter/Latest")] + [HttpGet("{id}/Chapter/LatestAvailable")] [ProducesResponseType(Status200OK, "application/json")] [ProducesResponseType(Status204NoContent)] [ProducesResponseType(Status404NotFound)] @@ -176,6 +176,36 @@ public class MangaController(PgsqlContext context) : Controller return Ok(max); } + /// + /// Returns the latest Chapter of requested Manga that is downloaded + /// + /// Manga-ID + /// + /// No available chapters + /// Manga with ID not found. + /// Could not retrieve the maximum chapter-number + [HttpGet("{id}/Chapter/LatestDownloaded")] + [ProducesResponseType(Status200OK, "application/json")] + [ProducesResponseType(Status204NoContent)] + [ProducesResponseType(Status404NotFound)] + [ProducesResponseType(Status500InternalServerError, "text/plain")] + public IActionResult GetLatestChapterDownloaded(string id) + { + Manga? m = context.Manga.Find(id); + if (m is null) + return NotFound(); + + List chapters = context.Chapters.Where(c => c.ParentMangaId == m.MangaId && c.Downloaded == true).ToList(); + if (chapters.Count == 0) + return NoContent(); + + Chapter? max = chapters.Max(); + if (max is null) + return StatusCode(500, "Max chapter could not be found"); + + return Ok(max); + } + /// /// Configure the cut-off for Manga ///