diff --git a/API/Schema/Chapter.cs b/API/Schema/Chapter.cs index d592b84..575df24 100644 --- a/API/Schema/Chapter.cs +++ b/API/Schema/Chapter.cs @@ -2,6 +2,7 @@ using System.Xml.Linq; using API.Schema.Jobs; using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; namespace API.Schema; @@ -38,6 +39,7 @@ public class Chapter : IComparable<Chapter> public bool Downloaded { get; internal set; } = false; public string ParentMangaId { get; internal set; } + [JsonIgnore] public Manga? ParentManga { get; init; } public int CompareTo(Chapter? other) diff --git a/API/Schema/Jobs/DownloadMangaCoverJob.cs b/API/Schema/Jobs/DownloadMangaCoverJob.cs index 1d75886..eba5ab1 100644 --- a/API/Schema/Jobs/DownloadMangaCoverJob.cs +++ b/API/Schema/Jobs/DownloadMangaCoverJob.cs @@ -3,6 +3,7 @@ using System.IO.Compression; using System.Runtime.InteropServices; using API.MangaDownloadClients; using API.Schema.MangaConnectors; +using Newtonsoft.Json; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Processing; @@ -16,6 +17,7 @@ public class DownloadMangaCoverJob(string mangaId, string? parentJobId = null, I { [MaxLength(64)] public string MangaId { get; init; } = mangaId; + [JsonIgnore] public Manga? Manga { get; init; } protected override IEnumerable<Job> RunInternal(PgsqlContext context) diff --git a/API/Schema/Jobs/DownloadNewChaptersJob.cs b/API/Schema/Jobs/DownloadNewChaptersJob.cs index b00472e..cade8e2 100644 --- a/API/Schema/Jobs/DownloadNewChaptersJob.cs +++ b/API/Schema/Jobs/DownloadNewChaptersJob.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations; using API.Schema.MangaConnectors; +using Newtonsoft.Json; namespace API.Schema.Jobs; @@ -8,6 +9,8 @@ public class DownloadNewChaptersJob(ulong recurrenceMs, string mangaId, string? { [MaxLength(64)] public string MangaId { get; init; } = mangaId; + + [JsonIgnore] public Manga? Manga { get; init; } protected override IEnumerable<Job> RunInternal(PgsqlContext context) diff --git a/API/Schema/Jobs/DownloadSingleChapterJob.cs b/API/Schema/Jobs/DownloadSingleChapterJob.cs index 0b79889..f7aa0ac 100644 --- a/API/Schema/Jobs/DownloadSingleChapterJob.cs +++ b/API/Schema/Jobs/DownloadSingleChapterJob.cs @@ -3,6 +3,7 @@ using System.IO.Compression; using System.Runtime.InteropServices; using API.MangaDownloadClients; using API.Schema.MangaConnectors; +using Newtonsoft.Json; using SixLabors.ImageSharp; using SixLabors.ImageSharp.Formats.Jpeg; using SixLabors.ImageSharp.Processing; @@ -16,6 +17,8 @@ public class DownloadSingleChapterJob(string chapterId, string? parentJobId = nu { [MaxLength(64)] public string ChapterId { get; init; } = chapterId; + + [JsonIgnore] public Chapter? Chapter { get; init; } protected override IEnumerable<Job> RunInternal(PgsqlContext context) diff --git a/API/Schema/Jobs/Job.cs b/API/Schema/Jobs/Job.cs index 866eacc..330bcb2 100644 --- a/API/Schema/Jobs/Job.cs +++ b/API/Schema/Jobs/Job.cs @@ -13,10 +13,12 @@ public abstract class Job [MaxLength(64)] public string? ParentJobId { get; init; } + [JsonIgnore] public Job? ParentJob { get; init; } [MaxLength(64)] public ICollection<string>? DependsOnJobsIds { get; init; } + [JsonIgnore] public ICollection<Job>? DependsOnJobs { get; init; } public JobType JobType { get; init; } diff --git a/API/Schema/Jobs/JobJsonDeserializer.cs b/API/Schema/Jobs/JobJsonDeserializer.cs deleted file mode 100644 index 071a3f0..0000000 --- a/API/Schema/Jobs/JobJsonDeserializer.cs +++ /dev/null @@ -1,29 +0,0 @@ -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using JsonSerializer = Newtonsoft.Json.JsonSerializer; - -namespace API.Schema.Jobs; - -public class JobJsonDeserializer : JsonConverter<Job> -{ - public override bool CanWrite { get; } = false; - - public override void WriteJson(JsonWriter writer, Job? value, JsonSerializer serializer) - { - throw new NotImplementedException(); - } - - public override Job? ReadJson(JsonReader reader, Type objectType, Job? existingValue, bool hasExistingValue, JsonSerializer serializer) - { - JObject j = JObject.Load(reader); - JobType? type = Enum.Parse<JobType>(j.GetValue("jobType")!.Value<string>()!); - return type switch - { - JobType.DownloadSingleChapterJob => j.ToObject<DownloadSingleChapterJob>(), - JobType.DownloadNewChaptersJob => j.ToObject<DownloadNewChaptersJob>(), - JobType.UpdateMetaDataJob => j.ToObject<UpdateMetadataJob>(), - JobType.MoveFileOrFolderJob => j.ToObject<MoveFileOrFolderJob>(), - _ => null - }; - } -} \ No newline at end of file diff --git a/API/Schema/Jobs/UpdateMetadataJob.cs b/API/Schema/Jobs/UpdateMetadataJob.cs index b214731..a4bca95 100644 --- a/API/Schema/Jobs/UpdateMetadataJob.cs +++ b/API/Schema/Jobs/UpdateMetadataJob.cs @@ -1,5 +1,6 @@ using System.ComponentModel.DataAnnotations; using API.Schema.MangaConnectors; +using Newtonsoft.Json; namespace API.Schema.Jobs; @@ -8,6 +9,8 @@ public class UpdateMetadataJob(ulong recurrenceMs, string mangaId, string? paren { [MaxLength(64)] public string MangaId { get; init; } = mangaId; + + [JsonIgnore] public virtual Manga? Manga { get; init; } /// <summary> diff --git a/API/Schema/Manga.cs b/API/Schema/Manga.cs index f87ec30..82c7cb6 100644 --- a/API/Schema/Manga.cs +++ b/API/Schema/Manga.cs @@ -1,3 +1,4 @@ +using System.Collections; using System.ComponentModel.DataAnnotations; using System.Net; using System.Runtime.InteropServices; @@ -6,6 +7,7 @@ using API.MangaDownloadClients; using API.Schema.Jobs; using API.Schema.MangaConnectors; using Microsoft.EntityFrameworkCore; +using Newtonsoft.Json; using static System.IO.UnixFileMode; namespace API.Schema; @@ -30,15 +32,23 @@ public class Manga public float IgnoreChapterBefore { get; internal set; } public string MangaConnectorId { get; private set; } - + [JsonIgnore] public MangaConnector? MangaConnector { get; private set; } + public ICollection<string> AuthorIds { get; internal set; } + [JsonIgnore] public ICollection<Author>? Authors { get; internal set; } + public ICollection<string> TagIds { get; internal set; } + [JsonIgnore] public ICollection<MangaTag>? Tags { get; internal set; } + public ICollection<string> LinkIds { get; internal set; } + [JsonIgnore] public ICollection<Link>? Links { get; internal set; } + public ICollection<string> AltTitleIds { get; internal set; } + [JsonIgnore] public ICollection<MangaAltTitle>? AltTitles { get; internal set; } public Manga(string connectorId, string name, string description, string websiteUrl, string coverUrl, @@ -48,9 +58,13 @@ public class Manga : this(connectorId, name, description, websiteUrl, coverUrl, coverFileNameInCache, year, originalLanguage, releaseStatus, ignoreChapterBefore, mangaConnector.Name) { + this.AuthorIds = authors.Select(a => a.AuthorId) as ICollection<string>; this.Authors = authors; + this.TagIds = tags.Select(t => t.Tag) as ICollection<string>; this.Tags = tags; + this.LinkIds = links.Select(l => l.LinkId) as ICollection<string>; this.Links = links; + this.AltTitleIds = altTitles.Select(t => t.AltTitleId) as ICollection<string>; this.AltTitles = altTitles; }