mirror of
https://github.com/C9Glax/tranga.git
synced 2025-09-10 11:58:19 +02:00
Use DTOs to return API requests instead of Database Schema types.
Make use of IHttpStatusCodeResults
This commit is contained in:
24
API/Controllers/DTOs/AltTitle.cs
Normal file
24
API/Controllers/DTOs/AltTitle.cs
Normal file
@@ -0,0 +1,24 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="API.Schema.MangaContext.AltTitle"/> DTO
|
||||
/// </summary>
|
||||
public sealed record AltTitle(string Language, string Title)
|
||||
{
|
||||
/// <summary>
|
||||
/// Language of the Title
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Language of the Title")]
|
||||
public string Language { get; init; } = Language;
|
||||
|
||||
/// <summary>
|
||||
/// Title
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Title")]
|
||||
public string Title { get; init; } = Title;
|
||||
}
|
17
API/Controllers/DTOs/Author.cs
Normal file
17
API/Controllers/DTOs/Author.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="API.Schema.MangaContext.Author"/> DTO
|
||||
/// </summary>
|
||||
public record Author(string Key, string Name) : Identifiable(Key)
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the Author.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Name of the Author.")]
|
||||
public string Name { get; init; } = Name;
|
||||
}
|
52
API/Controllers/DTOs/Chapter.cs
Normal file
52
API/Controllers/DTOs/Chapter.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="API.Schema.MangaContext.Chapter"/> DTO
|
||||
/// </summary>
|
||||
public record Chapter(string Key, string MangaId, int? Volume, string ChapterNumber, string? Title, IEnumerable<MangaConnectorId> MangaConnectorIds, bool Downloaded) : Identifiable(Key)
|
||||
{
|
||||
/// <summary>
|
||||
/// Identifier of the Manga this Chapter belongs to
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Identifier of the Manga this Chapter belongs to")]
|
||||
public string MangaId { get; init; } = MangaId;
|
||||
|
||||
/// <summary>
|
||||
/// Volume number
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Volume number")]
|
||||
public int? Volume { get; init; } = Volume;
|
||||
|
||||
/// <summary>
|
||||
/// Chapter number
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Chapter number")]
|
||||
public string ChapterNumber { get; init; } = ChapterNumber;
|
||||
|
||||
/// <summary>
|
||||
/// Title of the Chapter
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Title of the Chapter")]
|
||||
public string? Title { get; init; } = Title;
|
||||
|
||||
/// <summary>
|
||||
/// Whether Chapter is Downloaded (on disk)
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Whether Chapter is Downloaded (on disk)")]
|
||||
public bool Downloaded { get; init; } = Downloaded;
|
||||
|
||||
/// <summary>
|
||||
/// Ids of the Manga on MangaConnectors
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Ids of the Manga on MangaConnectors")]
|
||||
public IEnumerable<MangaConnectorId> MangaConnectorIds { get; init; } = MangaConnectorIds;
|
||||
}
|
18
API/Controllers/DTOs/Identifiable.cs
Normal file
18
API/Controllers/DTOs/Identifiable.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="API.Schema.Identifiable"/>
|
||||
/// </summary>
|
||||
public record Identifiable(string Key)
|
||||
{
|
||||
/// <summary>
|
||||
/// Unique Identifier of the DTO
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Unique Identifier of the DTO")]
|
||||
[StringLength(TokenGen.MaximumLength, MinimumLength = TokenGen.MinimumLength)]
|
||||
public string Key { get; init; } = Key;
|
||||
}
|
25
API/Controllers/DTOs/Link.cs
Normal file
25
API/Controllers/DTOs/Link.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="API.Schema.MangaContext.Link"/> DTO
|
||||
/// </summary>
|
||||
public sealed record Link(string Key, string Provider, string Url) : Identifiable(Key)
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the Provider
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Name of the Provider")]
|
||||
public string Provider { get; init; } = Provider;
|
||||
|
||||
/// <summary>
|
||||
/// Url
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Url")]
|
||||
public string Url { get; init; } = Url;
|
||||
}
|
66
API/Controllers/DTOs/Manga.cs
Normal file
66
API/Controllers/DTOs/Manga.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Schema.MangaContext;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="Schema.MangaContext.Manga"/> DTO
|
||||
/// </summary>
|
||||
public record Manga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus, IEnumerable<MangaConnectorId> MangaConnectorIds, float IgnoreChaptersBefore, uint? Year, string? OriginalLanguage, IEnumerable<string> ChapterIds, IEnumerable<Author> Authors, IEnumerable<string> Tags, IEnumerable<Link> Links, IEnumerable<AltTitle> AltTitles)
|
||||
: MinimalManga(Key, Name, Description, ReleaseStatus, MangaConnectorIds)
|
||||
{
|
||||
/// <summary>
|
||||
/// Chapter cutoff for Downloads (Chapters before this will not be downloaded)
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Chapter cutoff for Downloads (Chapters before this will not be downloaded)")]
|
||||
public float IgnoreChaptersBefore { get; init; } = IgnoreChaptersBefore;
|
||||
|
||||
/// <summary>
|
||||
/// Release Year
|
||||
/// </summary>
|
||||
[Description("Release Year")]
|
||||
public uint? Year { get; init; } = Year;
|
||||
|
||||
/// <summary>
|
||||
/// Release Language
|
||||
/// </summary>
|
||||
[Description("Release Language")]
|
||||
public string? OriginalLanguage { get; init; } = OriginalLanguage;
|
||||
|
||||
/// <summary>
|
||||
/// Keys of ChapterDTOs
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Keys of ChapterDTOs")]
|
||||
public IEnumerable<string> ChapterIds { get; init; } = ChapterIds;
|
||||
|
||||
/// <summary>
|
||||
/// Author-names
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Author-names")]
|
||||
public IEnumerable<Author> Authors { get; init; } = Authors;
|
||||
|
||||
/// <summary>
|
||||
/// Manga Tags
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Manga Tags")]
|
||||
public IEnumerable<string> Tags { get; init; } = Tags;
|
||||
|
||||
/// <summary>
|
||||
/// Links for more Metadata
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Links for more Metadata")]
|
||||
public IEnumerable<Link> Links { get; init; } = Links;
|
||||
|
||||
/// <summary>
|
||||
/// Alt Titles of Manga
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Alt Titles of Manga")]
|
||||
public IEnumerable<AltTitle> AltTitles { get; init; } = AltTitles;
|
||||
}
|
38
API/Controllers/DTOs/MangaConnectorId.cs
Normal file
38
API/Controllers/DTOs/MangaConnectorId.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Schema.MangaContext;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="MangaConnectorId{T}"/> DTO
|
||||
/// </summary>
|
||||
public sealed record MangaConnectorId(string Key, string MangaConnectorName, string ForeignKey, string? WebsiteUrl, bool UseForDownload) : Identifiable(Key)
|
||||
{
|
||||
/// <summary>
|
||||
/// Name of the Connector
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Name of the Connector")]
|
||||
public string MangaConnectorName { get; init; } = MangaConnectorName;
|
||||
|
||||
/// <summary>
|
||||
/// Key of the referenced DTO
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Key of the referenced DTO")]
|
||||
public string ForeignKey { get; init; } = ForeignKey;
|
||||
|
||||
/// <summary>
|
||||
/// Website Link for reference, if any
|
||||
/// </summary>
|
||||
[Description("Website Link for reference, if any")]
|
||||
public string? WebsiteUrl { get; init; } = WebsiteUrl;
|
||||
|
||||
/// <summary>
|
||||
/// Whether this Link is used for downloads
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Whether this Link is used for downloads")]
|
||||
public bool UseForDownload { get; init; } = UseForDownload;
|
||||
}
|
@@ -1,21 +1,39 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Schema.MangaContext;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
public sealed record MinimalManga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus, IEnumerable<MangaConnectorId<Manga>>? MangaConnectorIds = null)
|
||||
/// <summary>
|
||||
/// Shortened Version of <see cref="Manga"/>
|
||||
/// </summary>
|
||||
public record MinimalManga(string Key, string Name, string Description, MangaReleaseStatus ReleaseStatus, IEnumerable<MangaConnectorId> MangaConnectorIds) : Identifiable(Key)
|
||||
{
|
||||
[Required] [StringLength(TokenGen.MaximumLength, MinimumLength = TokenGen.MinimumLength)]
|
||||
public string Key { get; init; } = Key;
|
||||
/// <summary>
|
||||
/// Name of the Manga
|
||||
/// </summary>
|
||||
[Required]
|
||||
[JsonRequired]
|
||||
[Description("Name of the Manga")]
|
||||
public string Name { get; init; } = Name;
|
||||
|
||||
/// <summary>
|
||||
/// Description of the Manga
|
||||
/// </summary>
|
||||
[Required]
|
||||
[JsonRequired]
|
||||
[Description("Description of the Manga")]
|
||||
public string Description { get; init; } = Description;
|
||||
|
||||
/// <summary>
|
||||
/// ReleaseStatus of the Manga
|
||||
/// </summary>
|
||||
[Required]
|
||||
[JsonRequired]
|
||||
[Description("ReleaseStatus of the Manga")]
|
||||
public MangaReleaseStatus ReleaseStatus { get; init; } = ReleaseStatus;
|
||||
public IEnumerable<MangaConnectorId<Manga>>? MangaConnectorIds { get; init; } = MangaConnectorIds;
|
||||
|
||||
/// <summary>
|
||||
/// Ids of the Manga on MangaConnectors
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Ids of the Manga on MangaConnectors")]
|
||||
public IEnumerable<MangaConnectorId> MangaConnectorIds { get; init; } = MangaConnectorIds;
|
||||
}
|
33
API/Controllers/DTOs/PeriodicWorker.cs
Normal file
33
API/Controllers/DTOs/PeriodicWorker.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Workers;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="IPeriodic"/> DTO (<seealso cref="Worker"/> <seealso cref="BaseWorker"/>)
|
||||
/// </summary>
|
||||
public sealed record PeriodicWorker(string Key, IEnumerable<string> Dependencies, IEnumerable<string> MissingDependencies, bool DependenciesFulfilled, WorkerExecutionState State, DateTime LastExecution, TimeSpan Interval, DateTime NextExecution)
|
||||
: Worker(Key, Dependencies, MissingDependencies, DependenciesFulfilled, State)
|
||||
{
|
||||
/// <summary>
|
||||
/// Timestamp when Worker executed last.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Timestamp when Worker executed last.")]
|
||||
public DateTime LastExecution { get; init; } = LastExecution;
|
||||
|
||||
/// <summary>
|
||||
/// Interval at which Worker runs.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Interval at which Worker runs.")]
|
||||
public TimeSpan Interval { get; init; } = Interval;
|
||||
|
||||
/// <summary>
|
||||
/// Timestamp when Worker is scheduled to execute next.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Timestamp when Worker is scheduled to execute next.")]
|
||||
public DateTime NextExecution { get; init; } = LastExecution;
|
||||
}
|
39
API/Controllers/DTOs/Worker.cs
Normal file
39
API/Controllers/DTOs/Worker.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using API.Workers;
|
||||
|
||||
namespace API.Controllers.DTOs;
|
||||
|
||||
/// <summary>
|
||||
/// <see cref="BaseWorker"/> DTO
|
||||
/// </summary>
|
||||
public record Worker(string Key, IEnumerable<string> Dependencies, IEnumerable<string> MissingDependencies, bool DependenciesFulfilled, WorkerExecutionState State) : Identifiable(Key)
|
||||
{
|
||||
/// <summary>
|
||||
/// Workers this worker depends on having ran.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Workers this worker depends on having ran.")]
|
||||
public IEnumerable<string> Dependencies { get; init; } = Dependencies;
|
||||
|
||||
/// <summary>
|
||||
/// Workers that have not yet ran, that need to run for this Worker to run.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Workers that have not yet ran, that need to run for this Worker to run.")]
|
||||
public IEnumerable<string> MissingDependencies { get; init; } = MissingDependencies;
|
||||
|
||||
/// <summary>
|
||||
/// Worker can run.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Worker can run.")]
|
||||
public bool DependenciesFulfilled { get; init; } = DependenciesFulfilled;
|
||||
|
||||
/// <summary>
|
||||
/// Execution state of the Worker.
|
||||
/// </summary>
|
||||
[Required]
|
||||
[Description("Execution state of the Worker.")]
|
||||
public WorkerExecutionState State { get; init; } = State;
|
||||
}
|
Reference in New Issue
Block a user