From c23d29436f177d2b996be92139e212752856c10f Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 3 Sep 2025 17:55:26 +0200 Subject: [PATCH] MangaConnector DTO --- API/Controllers/DTOs/MangaConnector.cs | 28 ++++++++++++++++ API/Controllers/MangaConnectorController.cs | 36 +++++++++++++-------- API/Controllers/MangaController.cs | 23 +++++++------ API/Controllers/SearchController.cs | 1 - API/MangaConnectors/MangaConnector.cs | 25 ++++---------- 5 files changed, 67 insertions(+), 46 deletions(-) create mode 100644 API/Controllers/DTOs/MangaConnector.cs diff --git a/API/Controllers/DTOs/MangaConnector.cs b/API/Controllers/DTOs/MangaConnector.cs new file mode 100644 index 0000000..7728a3a --- /dev/null +++ b/API/Controllers/DTOs/MangaConnector.cs @@ -0,0 +1,28 @@ +using System.ComponentModel; +using System.ComponentModel.DataAnnotations; + +namespace API.Controllers.DTOs; + +public sealed record MangaConnector(string Name, bool Enabled, string IconUrl, string[] SupportedLanguages) : Identifiable(Name) +{ + /// + /// Whether Connector is used for Searches and Downloads + /// + [Required] + [Description("Whether Connector is used for Searches and Downloads")] + public bool Enabled { get; init; } = Enabled; + + /// + /// Languages supported by the Connector + /// + [Required] + [Description("Languages supported by the Connector")] + public string[] SupportedLanguages { get; init; } = SupportedLanguages; + + /// + /// Url of the Website Icon + /// + [Required] + [Description("Url of the Website Icon")] + public string IconUrl { get; init; } = IconUrl; +} \ No newline at end of file diff --git a/API/Controllers/MangaConnectorController.cs b/API/Controllers/MangaConnectorController.cs index faf7fa9..c4e428f 100644 --- a/API/Controllers/MangaConnectorController.cs +++ b/API/Controllers/MangaConnectorController.cs @@ -1,4 +1,4 @@ -using API.MangaConnectors; +using API.Controllers.DTOs; using API.Schema.MangaContext; using Asp.Versioning; using Microsoft.AspNetCore.Http.HttpResults; @@ -14,20 +14,22 @@ namespace API.Controllers; public class MangaConnectorController(MangaContext context) : Controller { /// - /// Get all (Scanlation-Sites) + /// Get all (Scanlation-Sites) /// - /// Names of (Scanlation-Sites) + /// Names of (Scanlation-Sites) [HttpGet] [ProducesResponseType>(Status200OK, "application/json")] public Ok> GetConnectors() { - return TypedResults.Ok(Tranga.MangaConnectors.ToList()); + return TypedResults.Ok(Tranga.MangaConnectors + .Select(c => new MangaConnector(c.Name, c.Enabled, c.IconUrl, c.SupportedLanguages)) + .ToList()); } /// - /// Returns the (Scanlation-Sites) with the requested Name + /// Returns the (Scanlation-Sites) with the requested Name /// - /// .Name + /// .Name /// /// (Scanlation-Sites) with Name not found. [HttpGet("{MangaConnectorName}")] @@ -38,22 +40,25 @@ public class MangaConnectorController(MangaContext context) : Controller if(Tranga.MangaConnectors.FirstOrDefault(c => c.Name.Equals(MangaConnectorName, StringComparison.InvariantCultureIgnoreCase)) is not { } connector) return TypedResults.NotFound(nameof(MangaConnectorName)); - return TypedResults.Ok(connector); + return TypedResults.Ok(new MangaConnector(connector.Name, connector.Enabled, connector.IconUrl, connector.SupportedLanguages)); } /// - /// Get all enabled (Scanlation-Sites) + /// Get all enabled (Scanlation-Sites) /// /// [HttpGet("Enabled")] [ProducesResponseType>(Status200OK, "application/json")] public Ok> GetEnabledConnectors() { - return TypedResults.Ok(Tranga.MangaConnectors.Where(c => c.Enabled).ToList()); + return TypedResults.Ok(Tranga.MangaConnectors + .Where(c => c.Enabled) + .Select(c => new MangaConnector(c.Name, c.Enabled, c.IconUrl, c.SupportedLanguages)) + .ToList()); } /// - /// Get all disabled (Scanlation-Sites) + /// Get all disabled (Scanlation-Sites) /// /// [HttpGet("Disabled")] @@ -61,16 +66,19 @@ public class MangaConnectorController(MangaContext context) : Controller public Ok> GetDisabledConnectors() { - return TypedResults.Ok(Tranga.MangaConnectors.Where(c => c.Enabled == false).ToList()); + return TypedResults.Ok(Tranga.MangaConnectors + .Where(c => c.Enabled == false) + .Select(c => new MangaConnector(c.Name, c.Enabled, c.IconUrl, c.SupportedLanguages)) + .ToList()); } /// - /// Enabled or disables (Scanlation-Sites) with Name + /// Enabled or disables (Scanlation-Sites) with Name /// - /// .Name + /// .Name /// Set true to enable, false to disable /// - /// (Scanlation-Sites) with Name not found. + /// (Scanlation-Sites) with Name not found. /// Error during Database Operation [HttpPatch("{MangaConnectorName}/SetEnabled/{Enabled}")] [ProducesResponseType(Status200OK)] diff --git a/API/Controllers/MangaController.cs b/API/Controllers/MangaController.cs index f6b5180..aaea9a3 100644 --- a/API/Controllers/MangaController.cs +++ b/API/Controllers/MangaController.cs @@ -1,5 +1,4 @@ using API.Controllers.DTOs; -using API.MangaConnectors; using API.Schema.MangaContext; using API.Workers; using Asp.Versioning; @@ -67,7 +66,7 @@ public class MangaController(MangaContext context) : Controller } /// - /// Returns all that are being downloaded from at least one + /// Returns all that are being downloaded from at least one /// /// exert of . Use for more information /// Error during Database Operation @@ -320,7 +319,7 @@ public class MangaController(MangaContext context) : Controller } /// - /// Returns the latest of requested available on + /// Returns the latest of requested available on /// /// .Key /// @@ -457,15 +456,15 @@ public class MangaController(MangaContext context) : Controller } /// - /// (Un-)Marks as requested for Download from + /// (Un-)Marks as requested for Download from /// /// with - /// with + /// with /// true to mark as requested, false to mark as not-requested /// /// or not found - /// was not linked to , so nothing changed - /// is not linked to yet. Search for on first (to create a ). + /// was not linked to , so nothing changed + /// is not linked to yet. Search for on first (to create a ). /// Error during Database Operation [HttpPost("{MangaId}/SetAsDownloadFrom/{MangaConnectorName}/{IsRequested}")] [ProducesResponseType(Status200OK)] @@ -477,7 +476,7 @@ public class MangaController(MangaContext context) : Controller { if (await context.Mangas.FirstOrDefaultAsync(m => m.Key == MangaId, HttpContext.RequestAborted) is not { } _) return TypedResults.NotFound(nameof(MangaId)); - if(!Tranga.TryGetMangaConnector(MangaConnectorName, out MangaConnector? _)) + if(!Tranga.TryGetMangaConnector(MangaConnectorName, out API.MangaConnectors.MangaConnector? _)) return TypedResults.NotFound(nameof(MangaConnectorName)); if (context.MangaConnectorToManga @@ -502,13 +501,13 @@ public class MangaController(MangaContext context) : Controller } /// - /// Initiate a search for on a different + /// Initiate a search for on a different /// /// with - /// .Name + /// .Name /// exert of - /// with Name not found - /// with Name is disabled + /// with Name not found + /// with Name is disabled [HttpPost("{MangaId}/SearchOn/{MangaConnectorName}")] [ProducesResponseType>(Status200OK, "application/json")] [ProducesResponseType(Status404NotFound, "text/plain")] diff --git a/API/Controllers/SearchController.cs b/API/Controllers/SearchController.cs index d337e42..d059d93 100644 --- a/API/Controllers/SearchController.cs +++ b/API/Controllers/SearchController.cs @@ -1,5 +1,4 @@ using API.Controllers.DTOs; -using API.MangaConnectors; using API.Schema.MangaContext; using Asp.Versioning; using Microsoft.AspNetCore.Http.HttpResults; diff --git a/API/MangaConnectors/MangaConnector.cs b/API/MangaConnectors/MangaConnector.cs index 31fc0b9..d02718a 100644 --- a/API/MangaConnectors/MangaConnector.cs +++ b/API/MangaConnectors/MangaConnector.cs @@ -12,27 +12,14 @@ namespace API.MangaConnectors; [PrimaryKey("Name")] public abstract class MangaConnector(string name, string[] supportedLanguages, string[] baseUris, string iconUrl) { - [JsonIgnore] - [NotMapped] - internal DownloadClient downloadClient { get; init; } = null!; + [NotMapped] internal DownloadClient downloadClient { get; init; } = null!; - [JsonIgnore] - [NotMapped] - protected ILog Log { get; init; } = LogManager.GetLogger(name); + [NotMapped] protected ILog Log { get; init; } = LogManager.GetLogger(name); - [StringLength(32)] - [Required] - public string Name { get; init; } = name; - [StringLength(8)] - [Required] - public string[] SupportedLanguages { get; init; } = supportedLanguages; - [StringLength(2048)] - [Required] - public string IconUrl { get; init; } = iconUrl; - [StringLength(256)] - [Required] - public string[] BaseUris { get; init; } = baseUris; - [Required] + [StringLength(32)] public string Name { get; init; } = name; + [StringLength(8)] public string[] SupportedLanguages { get; init; } = supportedLanguages; + [StringLength(2048)] public string IconUrl { get; init; } = iconUrl; + [StringLength(256)] public string[] BaseUris { get; init; } = baseUris; public bool Enabled { get; internal set; } = true; public abstract (Manga, MangaConnectorId)[] SearchManga(string mangaSearchName);