diff --git a/API/Controllers/JobController.cs b/API/Controllers/JobController.cs index 303f36a..6b71294 100644 --- a/API/Controllers/JobController.cs +++ b/API/Controllers/JobController.cs @@ -214,7 +214,7 @@ public class JobController(PgsqlContext context) : Controller /// Job modified /// Malformed request /// Job with ID not found - /// Internal Error + /// Error during Database Operation [HttpPatch("{id}/")] [ProducesResponseType(Status202Accepted)] [ProducesResponseType(Status400BadRequest)] @@ -247,7 +247,7 @@ public class JobController(PgsqlContext context) : Controller /// Job started /// Job with ID not found /// Job was already running - /// Internal Error + /// Error during Database Operation [HttpPost("{id}/Start")] [ProducesResponseType(Status202Accepted)] [ProducesResponseType(Status404NotFound)] @@ -276,19 +276,10 @@ public class JobController(PgsqlContext context) : Controller /// Stops the Job with the requested ID /// /// Job-ID - /// Job started - /// Job with ID not found - /// Job was not running - /// Internal Error /// NOT IMPLEMENTED - [ProducesResponseType(Status202Accepted)] - [ProducesResponseType(Status404NotFound)] - [ProducesResponseType(Status409Conflict)] - [ProducesResponseType(Status500InternalServerError)] [HttpPost("{id}/Stop")] public IActionResult StopJob(string id) { throw new NotImplementedException(); - return NotFound(new ProblemResponse("Not implemented")); } } \ No newline at end of file diff --git a/API/Controllers/LibraryConnectorController.cs b/API/Controllers/LibraryConnectorController.cs index 69d034e..1660e14 100644 --- a/API/Controllers/LibraryConnectorController.cs +++ b/API/Controllers/LibraryConnectorController.cs @@ -15,7 +15,7 @@ public class LibraryConnectorController(PgsqlContext context) : Controller /// /// Gets all configured Library-Connectors /// - /// Array of configured Library-Connectors + /// [HttpGet] [ProducesResponseType(Status200OK)] public IActionResult GetAllConnectors() @@ -28,7 +28,8 @@ public class LibraryConnectorController(PgsqlContext context) : Controller /// Returns Library-Connector with requested ID /// /// Library-Connector-ID - /// Library-Connector + /// + /// Connector with ID not found. [HttpGet("{id}")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] @@ -46,7 +47,8 @@ public class LibraryConnectorController(PgsqlContext context) : Controller /// Creates a new Library-Connector /// /// Library-Connector - /// Nothing + /// + /// Error during Database Operation [HttpPut] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status500InternalServerError)] @@ -68,7 +70,9 @@ public class LibraryConnectorController(PgsqlContext context) : Controller /// Deletes the Library-Connector with the requested ID /// /// Library-Connector-ID - /// Nothing + /// + /// Connector with ID not found. + /// Error during Database Operation [HttpDelete("{id}")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] diff --git a/API/Controllers/MangaConnectorController.cs b/API/Controllers/MangaConnectorController.cs index 31d5a81..9c92ce2 100644 --- a/API/Controllers/MangaConnectorController.cs +++ b/API/Controllers/MangaConnectorController.cs @@ -15,7 +15,7 @@ public class MangaConnectorController(PgsqlContext context) : Controller /// /// Get all available Connectors (Scanlation-Sites) /// - /// List of all Connectors + /// [HttpGet("GetConnectors")] [ProducesResponseType(Status200OK)] public IActionResult GetConnectors() @@ -27,7 +27,7 @@ public class MangaConnectorController(PgsqlContext context) : Controller /// /// Get all enabled Connectors (Scanlation-Sites) /// - /// List of all enabled Connectors + /// [HttpGet("GetConnectors/enabled")] [ProducesResponseType(Status200OK)] public IActionResult GetEnabledConnectors() @@ -39,7 +39,7 @@ public class MangaConnectorController(PgsqlContext context) : Controller /// /// Get all disabled Connectors (Scanlation-Sites) /// - /// List of all enabled Connectors + /// [HttpGet("GetConnectors/disabled")] [ProducesResponseType(Status200OK)] public IActionResult GetDisabledConnectors() diff --git a/API/Controllers/MangaController.cs b/API/Controllers/MangaController.cs index 9863a17..c274014 100644 --- a/API/Controllers/MangaController.cs +++ b/API/Controllers/MangaController.cs @@ -14,7 +14,7 @@ public class MangaController(PgsqlContext context) : Controller /// /// Returns all cached Manga /// - /// Array of Manga + /// [HttpGet] [ProducesResponseType(Status200OK)] public IActionResult GetAllManga() @@ -27,7 +27,7 @@ public class MangaController(PgsqlContext context) : Controller /// Returns all cached Manga with IDs /// /// Array of Manga-IDs - /// Array of Manga + /// [HttpPost("WithIDs")] [ProducesResponseType(Status200OK)] public IActionResult GetManga([FromBody]string[] ids) @@ -40,42 +40,41 @@ public class MangaController(PgsqlContext context) : Controller /// Return Manga with ID /// /// Manga-ID - /// Manga + /// + /// Manga with ID not found [HttpGet("{id}")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] public IActionResult GetManga(string id) { Manga? ret = context.Manga.Find(id); - return (ret is not null) switch - { - true => Ok(ret), - false => NotFound() - }; + if (ret is null) + return NotFound(); + return Ok(ret); } /// /// Delete Manga with ID /// /// Manga-ID - /// Nothing + /// + /// Manga with ID not found + /// Error during Database Operation [HttpDelete("{id}")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] - [ProducesResponseType(Status500InternalServerError)] + [ProducesResponseType(Status500InternalServerError)] public IActionResult DeleteManga(string id) { try { Manga? ret = context.Manga.Find(id); - switch (ret is not null) - { - case true: - context.Remove(ret); - context.SaveChanges(); - return Ok(); - case false: return NotFound(); - } + if (ret is null) + return NotFound(); + + context.Remove(ret); + context.SaveChanges(); + return Ok(); } catch (Exception e) { @@ -87,28 +86,29 @@ public class MangaController(PgsqlContext context) : Controller /// Returns URL of Cover of Manga /// /// Manga-ID - /// URL of Cover + /// NOT IMPLEMENTED [HttpGet("{id}/Cover")] - [ProducesResponseType(Status500InternalServerError)] public IActionResult GetCover(string id) { - return StatusCode(500, "Not implemented"); //TODO + throw new NotImplementedException(); } /// /// Returns all Chapters of Manga /// /// Manga-ID - /// Array of Chapters + /// + /// Manga with ID not found [HttpGet("{id}/Chapters")] [ProducesResponseType(Status200OK)] - [ProducesResponseType(Status404NotFound)] + [ProducesResponseType(Status404NotFound)] public IActionResult GetChapters(string id) { Manga? m = context.Manga.Find(id); if (m is null) - return NotFound("Manga could not be found"); - Chapter[] ret = context.Chapters.Where(c => c.ParentManga.MangaId == m.MangaId).ToArray(); + return NotFound(); + + Chapter[] ret = context.Chapters.Where(c => c.ParentMangaId == m.MangaId).ToArray(); return Ok(ret); } @@ -116,35 +116,46 @@ public class MangaController(PgsqlContext context) : Controller /// Returns the latest Chapter of requested Manga /// /// Manga-ID - /// Latest Chapter + /// + /// No available chapters + /// Manga with ID not found. + /// Could not retrieve the maximum chapter-number [HttpGet("{id}/Chapter/Latest")] [ProducesResponseType(Status200OK)] - [ProducesResponseType(Status404NotFound)] + [ProducesResponseType(Status204NoContent)] + [ProducesResponseType(Status404NotFound)] + [ProducesResponseType(Status500InternalServerError)] public IActionResult GetLatestChapter(string id) { Manga? m = context.Manga.Find(id); if (m is null) - return NotFound("Manga could not be found"); - List chapters = context.Chapters.Where(c => c.ParentManga.MangaId == m.MangaId).ToList(); + return NotFound(); + + List chapters = context.Chapters.Where(c => c.ParentMangaId == m.MangaId).ToList(); + if (chapters.Count == 0) + return NoContent(); + Chapter? max = chapters.Max(); if (max is null) - return NotFound("Chapter could not be found"); + return StatusCode(500, "Max chapter could not be found"); + return Ok(max); } /// /// Configure the cut-off for Manga /// - /// This is important for the DownloadNewChapters-Job /// Manga-ID - /// Nothing + /// + /// Manga with ID not found. [HttpPatch("{id}/IgnoreChaptersBefore")] [ProducesResponseType(Status200OK)] + [ProducesResponseType(Status404NotFound)] public IActionResult IgnoreChaptersBefore(string id) { Manga? m = context.Manga.Find(id); if (m is null) - return NotFound("Manga could not be found"); + return NotFound(); return Ok(m.IgnoreChapterBefore); } @@ -153,11 +164,10 @@ public class MangaController(PgsqlContext context) : Controller /// /// Manga-ID /// New Directory-Path - /// Nothing + /// NOT IMPLEMENTED [HttpPost("{id}/MoveFolder")] - [ProducesResponseType(Status500InternalServerError)] public IActionResult MoveFolder(string id, [FromBody]string folder) { - return StatusCode(500, "Not implemented"); //TODO + throw new NotImplementedException(); } } \ No newline at end of file diff --git a/API/Controllers/NotificationConnectorController.cs b/API/Controllers/NotificationConnectorController.cs index 20315d6..58381d4 100644 --- a/API/Controllers/NotificationConnectorController.cs +++ b/API/Controllers/NotificationConnectorController.cs @@ -15,7 +15,7 @@ public class NotificationConnectorController(PgsqlContext context) : Controller /// /// Gets all configured Notification-Connectors /// - /// Array of configured Notification-Connectors + /// [HttpGet] [ProducesResponseType(Status200OK)] public IActionResult GetAllConnectors() @@ -28,7 +28,8 @@ public class NotificationConnectorController(PgsqlContext context) : Controller /// Returns Notification-Connector with requested ID /// /// Notification-Connector-ID - /// Notification-Connector + /// + /// NotificationConnector with ID not found [HttpGet("{id}")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] @@ -46,7 +47,8 @@ public class NotificationConnectorController(PgsqlContext context) : Controller /// Creates a new Notification-Connector /// /// Notification-Connector - /// Nothing + /// + /// Error during Database Operation [HttpPut] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status500InternalServerError)] @@ -68,7 +70,9 @@ public class NotificationConnectorController(PgsqlContext context) : Controller /// Deletes the Notification-Connector with the requested ID /// /// Notification-Connector-ID - /// Nothing + /// + /// NotificationConnector with ID not found + /// Error during Database Operation [HttpDelete("{id}")] [ProducesResponseType(Status200OK)] [ProducesResponseType(Status404NotFound)] @@ -78,14 +82,12 @@ public class NotificationConnectorController(PgsqlContext context) : Controller try { NotificationConnector? ret = context.NotificationConnectors.Find(id); - switch (ret is not null) - { - case true: - context.Remove(ret); - context.SaveChanges(); - return Ok(); - case false: return NotFound(); - } + if(ret is null) + return NotFound(); + + context.Remove(ret); + context.SaveChanges(); + return Ok(); } catch (Exception e) { diff --git a/API/Controllers/SearchController.cs b/API/Controllers/SearchController.cs index 3c45c8d..6c539f7 100644 --- a/API/Controllers/SearchController.cs +++ b/API/Controllers/SearchController.cs @@ -18,14 +18,17 @@ public class SearchController(PgsqlContext context) : Controller /// Initiate a search for a Manga on all Connectors /// /// Name/Title of the Manga - /// Array of Manga + /// + /// Error during Database Operation [HttpPost("{name}")] - [ProducesResponseType(Status500InternalServerError)] + [ProducesResponseType(Status200OK)] + [ProducesResponseType(Status500InternalServerError)] public IActionResult SearchMangaGlobal(string name) { List<(Manga, List?, List?, List?, List?)> allManga = new(); foreach (MangaConnector contextMangaConnector in context.MangaConnectors) allManga.AddRange(contextMangaConnector.GetManga(name)); + List retMangas = new(); foreach ((Manga? manga, List? authors, List? tags, List? links, List? altTitles) in allManga) { @@ -35,9 +38,9 @@ public class SearchController(PgsqlContext context) : Controller if(add is not null) retMangas.Add(add); } - catch (DbUpdateException) + catch (Exception e) { - return StatusCode(500, new ProblemResponse("An error occurred while processing your request.")); + return StatusCode(500, e); } } return Ok(retMangas.ToArray()); @@ -48,16 +51,23 @@ public class SearchController(PgsqlContext context) : Controller /// /// Manga-Connector-ID /// Name/Title of the Manga - /// Manga + /// + /// MangaConnector with ID not found + /// MangaConnector with ID is disabled + /// Error during Database Operation [HttpPost("{id}/{name}")] [ProducesResponseType(Status200OK)] - [ProducesResponseType(Status404NotFound)] - [ProducesResponseType(Status500InternalServerError)] + [ProducesResponseType(Status404NotFound)] + [ProducesResponseType(Status406NotAcceptable)] + [ProducesResponseType(Status500InternalServerError)] public IActionResult SearchManga(string id, string name) { MangaConnector? connector = context.MangaConnectors.Find(id); if (connector is null) - return NotFound(new ProblemResponse("Connector not found.")); + return NotFound(); + else if (connector.Enabled is false) + return StatusCode(406); + (Manga, List?, List?, List?, List?)[] mangas = connector.GetManga(name); List retMangas = new(); foreach ((Manga? manga, List? authors, List? tags, List? links, List? altTitles) in mangas) @@ -68,15 +78,15 @@ public class SearchController(PgsqlContext context) : Controller if(add is not null) retMangas.Add(add); } - catch (DbUpdateException e) + catch (Exception e) { - return StatusCode(500, new ProblemResponse("An error occurred while processing your request.", e.Message)); + return StatusCode(500, e.Message); } } return Ok(retMangas.ToArray()); } - + private Manga? AddMangaToContext(Manga? manga, List? authors, List? tags, List? links, List? altTitles) { @@ -144,7 +154,7 @@ public class SearchController(PgsqlContext context) : Controller context.Manga.Update(existing); else context.Manga.Add(manga); - + context.SaveChanges(); return existing ?? manga; } diff --git a/API/ProblemResponse.cs b/API/ProblemResponse.cs deleted file mode 100644 index b189690..0000000 --- a/API/ProblemResponse.cs +++ /dev/null @@ -1,3 +0,0 @@ -namespace API; - -public record ProblemResponse(string title, string? message = null); \ No newline at end of file diff --git a/API/TrangaSettings.cs b/API/TrangaSettings.cs index 8fb7782..87d1c49 100644 --- a/API/TrangaSettings.cs +++ b/API/TrangaSettings.cs @@ -118,7 +118,7 @@ public static class TrangaSettings ExportSettings(); } - public static void ResetRateLimits() + public static void ResetRequestLimits() { requestLimits = DefaultRequestLimits; ExportSettings();