From 626131b9b85ceb91eb275f73451329e596859878 Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 15 Oct 2025 23:41:26 +0200 Subject: [PATCH] Enums as string --- API/MangaDownloadClients/RequestType.cs | 13 +- ...20251015210617_ChangeEnumTypes.Designer.cs | 71 +++ .../Library/20251015210617_ChangeEnumTypes.cs | 34 ++ .../Library/LibraryContextModelSnapshot.cs | 12 +- ...20251015210521_ChangeEnumTypes.Designer.cs | 533 ++++++++++++++++++ .../Manga/20251015210521_ChangeEnumTypes.cs | 34 ++ .../Manga/MangaContextModelSnapshot.cs | 4 +- ...20251015210643_ChangeEnumTypes.Designer.cs | 92 +++ .../20251015210643_ChangeEnumTypes.cs | 34 ++ .../NotificationsContextModelSnapshot.cs | 6 +- API/Program.cs | 9 +- .../LibraryConnectors/LibraryConnector.cs | 7 +- API/Schema/MangaContext/Manga.cs | 13 +- .../NotificationsContext/Notification.cs | 9 +- API/Workers/RefreshLibrariesWorker.cs | 11 +- 15 files changed, 838 insertions(+), 44 deletions(-) create mode 100644 API/Migrations/Library/20251015210617_ChangeEnumTypes.Designer.cs create mode 100644 API/Migrations/Library/20251015210617_ChangeEnumTypes.cs create mode 100644 API/Migrations/Manga/20251015210521_ChangeEnumTypes.Designer.cs create mode 100644 API/Migrations/Manga/20251015210521_ChangeEnumTypes.cs create mode 100644 API/Migrations/Notifications/20251015210643_ChangeEnumTypes.Designer.cs create mode 100644 API/Migrations/Notifications/20251015210643_ChangeEnumTypes.cs diff --git a/API/MangaDownloadClients/RequestType.cs b/API/MangaDownloadClients/RequestType.cs index 855c3ed..471c35d 100644 --- a/API/MangaDownloadClients/RequestType.cs +++ b/API/MangaDownloadClients/RequestType.cs @@ -1,11 +1,10 @@ namespace API.MangaDownloadClients; -public enum RequestType : byte +public enum RequestType { - Default = 0, - MangaDexFeed = 1, - MangaImage = 2, - MangaCover = 3, - MangaDexImage = 5, - MangaInfo = 6 + Default, + MangaDexFeed, + MangaImage, + MangaCover, + MangaInfo } \ No newline at end of file diff --git a/API/Migrations/Library/20251015210617_ChangeEnumTypes.Designer.cs b/API/Migrations/Library/20251015210617_ChangeEnumTypes.Designer.cs new file mode 100644 index 0000000..0f5519e --- /dev/null +++ b/API/Migrations/Library/20251015210617_ChangeEnumTypes.Designer.cs @@ -0,0 +1,71 @@ +// +using API.Schema.LibraryContext; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace API.Migrations.Library +{ + [DbContext(typeof(LibraryContext))] + [Migration("20251015210617_ChangeEnumTypes")] + partial class ChangeEnumTypes + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector", b => + { + b.Property("Key") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Auth") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("BaseUrl") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LibraryType") + .HasColumnType("integer"); + + b.HasKey("Key"); + + b.ToTable("LibraryConnectors"); + + b.HasDiscriminator("LibraryType"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.Kavita", b => + { + b.HasBaseType("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector"); + + b.HasDiscriminator().HasValue(1); + }); + + modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.Komga", b => + { + b.HasBaseType("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector"); + + b.HasDiscriminator().HasValue(0); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/API/Migrations/Library/20251015210617_ChangeEnumTypes.cs b/API/Migrations/Library/20251015210617_ChangeEnumTypes.cs new file mode 100644 index 0000000..6a8fb2f --- /dev/null +++ b/API/Migrations/Library/20251015210617_ChangeEnumTypes.cs @@ -0,0 +1,34 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace API.Migrations.Library +{ + /// + public partial class ChangeEnumTypes : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "LibraryType", + table: "LibraryConnectors", + type: "integer", + nullable: false, + oldClrType: typeof(byte), + oldType: "smallint"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "LibraryType", + table: "LibraryConnectors", + type: "smallint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + } + } +} diff --git a/API/Migrations/Library/LibraryContextModelSnapshot.cs b/API/Migrations/Library/LibraryContextModelSnapshot.cs index 3424bce..f4bcf3c 100644 --- a/API/Migrations/Library/LibraryContextModelSnapshot.cs +++ b/API/Migrations/Library/LibraryContextModelSnapshot.cs @@ -16,7 +16,7 @@ namespace API.Migrations.Library { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "9.0.8") + .HasAnnotation("ProductVersion", "9.0.9") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); @@ -37,14 +37,14 @@ namespace API.Migrations.Library .HasMaxLength(256) .HasColumnType("character varying(256)"); - b.Property("LibraryType") - .HasColumnType("smallint"); + b.Property("LibraryType") + .HasColumnType("integer"); b.HasKey("Key"); b.ToTable("LibraryConnectors"); - b.HasDiscriminator("LibraryType"); + b.HasDiscriminator("LibraryType"); b.UseTphMappingStrategy(); }); @@ -53,14 +53,14 @@ namespace API.Migrations.Library { b.HasBaseType("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector"); - b.HasDiscriminator().HasValue((byte)1); + b.HasDiscriminator().HasValue(1); }); modelBuilder.Entity("API.Schema.LibraryContext.LibraryConnectors.Komga", b => { b.HasBaseType("API.Schema.LibraryContext.LibraryConnectors.LibraryConnector"); - b.HasDiscriminator().HasValue((byte)0); + b.HasDiscriminator().HasValue(0); }); #pragma warning restore 612, 618 } diff --git a/API/Migrations/Manga/20251015210521_ChangeEnumTypes.Designer.cs b/API/Migrations/Manga/20251015210521_ChangeEnumTypes.Designer.cs new file mode 100644 index 0000000..4e81dd9 --- /dev/null +++ b/API/Migrations/Manga/20251015210521_ChangeEnumTypes.Designer.cs @@ -0,0 +1,533 @@ +// +using API.Schema.MangaContext; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace API.Migrations.Manga +{ + [DbContext(typeof(MangaContext))] + [Migration("20251015210521_ChangeEnumTypes")] + partial class ChangeEnumTypes + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("API.MangaConnectors.MangaConnector", b => + { + b.Property("Name") + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.PrimitiveCollection("BaseUris") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("text[]"); + + b.Property("Enabled") + .HasColumnType("boolean"); + + b.Property("IconUrl") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.PrimitiveCollection("SupportedLanguages") + .IsRequired() + .HasMaxLength(8) + .HasColumnType("text[]"); + + b.HasKey("Name"); + + b.ToTable("MangaConnector"); + + b.HasDiscriminator("Name").HasValue("MangaConnector"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("API.Schema.MangaContext.Author", b => + { + b.Property("Key") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("AuthorName") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.HasKey("Key"); + + b.ToTable("Authors"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.Chapter", b => + { + b.Property("Key") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("ChapterNumber") + .IsRequired() + .HasMaxLength(10) + .HasColumnType("character varying(10)"); + + b.Property("Downloaded") + .HasColumnType("boolean"); + + b.Property("FileName") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("ParentMangaId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Title") + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("VolumeNumber") + .HasColumnType("integer"); + + b.HasKey("Key"); + + b.HasIndex("ParentMangaId"); + + b.ToTable("Chapters"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.FileLibrary", b => + { + b.Property("Key") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("BasePath") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("LibraryName") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.HasKey("Key"); + + b.ToTable("FileLibraries"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.Manga", b => + { + b.Property("Key") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("CoverFileNameInCache") + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.Property("CoverUrl") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.Property("Description") + .IsRequired() + .HasColumnType("text"); + + b.Property("DirectoryName") + .IsRequired() + .HasMaxLength(1024) + .HasColumnType("character varying(1024)"); + + b.Property("IgnoreChaptersBefore") + .HasColumnType("real"); + + b.Property("LibraryId") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Name") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.Property("OriginalLanguage") + .HasMaxLength(8) + .HasColumnType("character varying(8)"); + + b.Property("ReleaseStatus") + .HasColumnType("integer"); + + b.Property("Year") + .HasColumnType("bigint"); + + b.HasKey("Key"); + + b.HasIndex("LibraryId"); + + b.ToTable("Mangas"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId", b => + { + b.Property("Key") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("IdOnConnectorSite") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("MangaConnectorName") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("ObjId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("UseForDownload") + .HasColumnType("boolean"); + + b.Property("WebsiteUrl") + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.HasKey("Key"); + + b.HasIndex("ObjId"); + + b.ToTable("MangaConnectorToChapter"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId", b => + { + b.Property("Key") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("IdOnConnectorSite") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b.Property("MangaConnectorName") + .IsRequired() + .HasMaxLength(32) + .HasColumnType("character varying(32)"); + + b.Property("ObjId") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("UseForDownload") + .HasColumnType("boolean"); + + b.Property("WebsiteUrl") + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.HasKey("Key"); + + b.HasIndex("ObjId"); + + b.ToTable("MangaConnectorToManga"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.MangaTag", b => + { + b.Property("Tag") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.HasKey("Tag"); + + b.ToTable("Tags"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataEntry", b => + { + b.Property("MetadataFetcherName") + .HasColumnType("text"); + + b.Property("Identifier") + .HasColumnType("text"); + + b.Property("MangaId") + .IsRequired() + .HasColumnType("character varying(64)"); + + b.HasKey("MetadataFetcherName", "Identifier"); + + b.HasIndex("MangaId"); + + b.ToTable("MetadataEntries"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher", b => + { + b.Property("Name") + .HasColumnType("text"); + + b.Property("MetadataEntry") + .IsRequired() + .HasMaxLength(21) + .HasColumnType("character varying(21)"); + + b.HasKey("Name"); + + b.ToTable("MetadataFetcher"); + + b.HasDiscriminator("MetadataEntry").HasValue("MetadataFetcher"); + + b.UseTphMappingStrategy(); + }); + + modelBuilder.Entity("AuthorToManga", b => + { + b.Property("AuthorIds") + .HasColumnType("character varying(64)"); + + b.Property("MangaIds") + .HasColumnType("character varying(64)"); + + b.HasKey("AuthorIds", "MangaIds"); + + b.HasIndex("MangaIds"); + + b.ToTable("AuthorToManga"); + }); + + modelBuilder.Entity("MangaTagToManga", b => + { + b.Property("MangaTagIds") + .HasColumnType("character varying(64)"); + + b.Property("MangaIds") + .HasColumnType("character varying(64)"); + + b.HasKey("MangaTagIds", "MangaIds"); + + b.HasIndex("MangaIds"); + + b.ToTable("MangaTagToManga"); + }); + + modelBuilder.Entity("API.MangaConnectors.Global", b => + { + b.HasBaseType("API.MangaConnectors.MangaConnector"); + + b.HasDiscriminator().HasValue("Global"); + }); + + modelBuilder.Entity("API.MangaConnectors.MangaDex", b => + { + b.HasBaseType("API.MangaConnectors.MangaConnector"); + + b.HasDiscriminator().HasValue("MangaDex"); + }); + + modelBuilder.Entity("API.MangaConnectors.MangaPark", b => + { + b.HasBaseType("API.MangaConnectors.MangaConnector"); + + b.HasDiscriminator().HasValue("MangaPark"); + }); + + modelBuilder.Entity("API.MangaConnectors.Mangaworld", b => + { + b.HasBaseType("API.MangaConnectors.MangaConnector"); + + b.HasDiscriminator().HasValue("Mangaworld"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MyAnimeList", b => + { + b.HasBaseType("API.Schema.MangaContext.MetadataFetchers.MetadataFetcher"); + + b.HasDiscriminator().HasValue("MyAnimeList"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.Chapter", b => + { + b.HasOne("API.Schema.MangaContext.Manga", "ParentManga") + .WithMany("Chapters") + .HasForeignKey("ParentMangaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("ParentManga"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.Manga", b => + { + b.HasOne("API.Schema.MangaContext.FileLibrary", "Library") + .WithMany() + .HasForeignKey("LibraryId") + .OnDelete(DeleteBehavior.SetNull); + + b.OwnsMany("API.Schema.MangaContext.AltTitle", "AltTitles", b1 => + { + b1.Property("Key") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b1.Property("Language") + .IsRequired() + .HasMaxLength(8) + .HasColumnType("character varying(8)"); + + b1.Property("MangaKey") + .IsRequired() + .HasColumnType("character varying(64)"); + + b1.Property("Title") + .IsRequired() + .HasMaxLength(256) + .HasColumnType("character varying(256)"); + + b1.HasKey("Key"); + + b1.HasIndex("MangaKey"); + + b1.ToTable("AltTitle"); + + b1.WithOwner() + .HasForeignKey("MangaKey"); + }); + + b.OwnsMany("API.Schema.MangaContext.Link", "Links", b1 => + { + b1.Property("Key") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b1.Property("LinkProvider") + .IsRequired() + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b1.Property("LinkUrl") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b1.Property("MangaKey") + .IsRequired() + .HasColumnType("character varying(64)"); + + b1.HasKey("Key"); + + b1.HasIndex("MangaKey"); + + b1.ToTable("Link"); + + b1.WithOwner() + .HasForeignKey("MangaKey"); + }); + + b.Navigation("AltTitles"); + + b.Navigation("Library"); + + b.Navigation("Links"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId", b => + { + b.HasOne("API.Schema.MangaContext.Chapter", "Obj") + .WithMany("MangaConnectorIds") + .HasForeignKey("ObjId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Obj"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.MangaConnectorId", b => + { + b.HasOne("API.Schema.MangaContext.Manga", "Obj") + .WithMany("MangaConnectorIds") + .HasForeignKey("ObjId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Obj"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.MetadataFetchers.MetadataEntry", b => + { + b.HasOne("API.Schema.MangaContext.Manga", "Manga") + .WithMany() + .HasForeignKey("MangaId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.Navigation("Manga"); + }); + + modelBuilder.Entity("AuthorToManga", b => + { + b.HasOne("API.Schema.MangaContext.Author", null) + .WithMany() + .HasForeignKey("AuthorIds") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("API.Schema.MangaContext.Manga", null) + .WithMany() + .HasForeignKey("MangaIds") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("MangaTagToManga", b => + { + b.HasOne("API.Schema.MangaContext.Manga", null) + .WithMany() + .HasForeignKey("MangaIds") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + + b.HasOne("API.Schema.MangaContext.MangaTag", null) + .WithMany() + .HasForeignKey("MangaTagIds") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired(); + }); + + modelBuilder.Entity("API.Schema.MangaContext.Chapter", b => + { + b.Navigation("MangaConnectorIds"); + }); + + modelBuilder.Entity("API.Schema.MangaContext.Manga", b => + { + b.Navigation("Chapters"); + + b.Navigation("MangaConnectorIds"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/API/Migrations/Manga/20251015210521_ChangeEnumTypes.cs b/API/Migrations/Manga/20251015210521_ChangeEnumTypes.cs new file mode 100644 index 0000000..a0f6916 --- /dev/null +++ b/API/Migrations/Manga/20251015210521_ChangeEnumTypes.cs @@ -0,0 +1,34 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace API.Migrations.Manga +{ + /// + public partial class ChangeEnumTypes : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ReleaseStatus", + table: "Mangas", + type: "integer", + nullable: false, + oldClrType: typeof(byte), + oldType: "smallint"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "ReleaseStatus", + table: "Mangas", + type: "smallint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + } + } +} diff --git a/API/Migrations/Manga/MangaContextModelSnapshot.cs b/API/Migrations/Manga/MangaContextModelSnapshot.cs index 2b89918..d809167 100644 --- a/API/Migrations/Manga/MangaContextModelSnapshot.cs +++ b/API/Migrations/Manga/MangaContextModelSnapshot.cs @@ -168,8 +168,8 @@ namespace API.Migrations.Manga .HasMaxLength(8) .HasColumnType("character varying(8)"); - b.Property("ReleaseStatus") - .HasColumnType("smallint"); + b.Property("ReleaseStatus") + .HasColumnType("integer"); b.Property("Year") .HasColumnType("bigint"); diff --git a/API/Migrations/Notifications/20251015210643_ChangeEnumTypes.Designer.cs b/API/Migrations/Notifications/20251015210643_ChangeEnumTypes.Designer.cs new file mode 100644 index 0000000..daa5ee5 --- /dev/null +++ b/API/Migrations/Notifications/20251015210643_ChangeEnumTypes.Designer.cs @@ -0,0 +1,92 @@ +// +using System; +using System.Collections.Generic; +using API.Schema.NotificationsContext; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace API.Migrations.Notifications +{ + [DbContext(typeof(NotificationsContext))] + [Migration("20251015210643_ChangeEnumTypes")] + partial class ChangeEnumTypes + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "9.0.9") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore"); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("API.Schema.NotificationsContext.Notification", b => + { + b.Property("Key") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Date") + .HasColumnType("timestamp with time zone"); + + b.Property("IsSent") + .HasColumnType("boolean"); + + b.Property("Message") + .IsRequired() + .HasMaxLength(512) + .HasColumnType("character varying(512)"); + + b.Property("Title") + .IsRequired() + .HasMaxLength(128) + .HasColumnType("character varying(128)"); + + b.Property("Urgency") + .HasColumnType("integer"); + + b.HasKey("Key"); + + b.ToTable("Notifications"); + }); + + modelBuilder.Entity("API.Schema.NotificationsContext.NotificationConnectors.NotificationConnector", b => + { + b.Property("Name") + .HasMaxLength(64) + .HasColumnType("character varying(64)"); + + b.Property("Body") + .IsRequired() + .HasMaxLength(4096) + .HasColumnType("character varying(4096)"); + + b.Property>("Headers") + .IsRequired() + .HasColumnType("hstore"); + + b.Property("HttpMethod") + .IsRequired() + .HasMaxLength(8) + .HasColumnType("character varying(8)"); + + b.Property("Url") + .IsRequired() + .HasMaxLength(2048) + .HasColumnType("character varying(2048)"); + + b.HasKey("Name"); + + b.ToTable("NotificationConnectors"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/API/Migrations/Notifications/20251015210643_ChangeEnumTypes.cs b/API/Migrations/Notifications/20251015210643_ChangeEnumTypes.cs new file mode 100644 index 0000000..4cd5709 --- /dev/null +++ b/API/Migrations/Notifications/20251015210643_ChangeEnumTypes.cs @@ -0,0 +1,34 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace API.Migrations.Notifications +{ + /// + public partial class ChangeEnumTypes : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Urgency", + table: "Notifications", + type: "integer", + nullable: false, + oldClrType: typeof(byte), + oldType: "smallint"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.AlterColumn( + name: "Urgency", + table: "Notifications", + type: "smallint", + nullable: false, + oldClrType: typeof(int), + oldType: "integer"); + } + } +} diff --git a/API/Migrations/Notifications/NotificationsContextModelSnapshot.cs b/API/Migrations/Notifications/NotificationsContextModelSnapshot.cs index 47db7b6..a6e262a 100644 --- a/API/Migrations/Notifications/NotificationsContextModelSnapshot.cs +++ b/API/Migrations/Notifications/NotificationsContextModelSnapshot.cs @@ -18,7 +18,7 @@ namespace API.Migrations.Notifications { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "9.0.8") + .HasAnnotation("ProductVersion", "9.0.9") .HasAnnotation("Relational:MaxIdentifierLength", 63); NpgsqlModelBuilderExtensions.HasPostgresExtension(modelBuilder, "hstore"); @@ -46,8 +46,8 @@ namespace API.Migrations.Notifications .HasMaxLength(128) .HasColumnType("character varying(128)"); - b.Property("Urgency") - .HasColumnType("smallint"); + b.Property("Urgency") + .HasColumnType("integer"); b.HasKey("Key"); diff --git a/API/Program.cs b/API/Program.cs index 99bed28..e184399 100644 --- a/API/Program.cs +++ b/API/Program.cs @@ -10,7 +10,6 @@ using log4net; using log4net.Config; using Microsoft.EntityFrameworkCore; using Microsoft.OpenApi; -using Newtonsoft.Json; using Newtonsoft.Json.Converters; using Npgsql; @@ -94,14 +93,16 @@ builder.Services.AddDbContext(options => builder.Services.AddDbContext(options => options.UseNpgsql(connectionStringBuilder.ConnectionString)); +builder.Services.Configure(options => +{ + options.SerializerOptions.Converters.Add(new System.Text.Json.Serialization.JsonStringEnumConverter()); +}); builder.Services.AddControllers(options => { options.AllowEmptyInputInBodyModelBinding = true; -}); -builder.Services.AddControllers().AddNewtonsoftJson(opts => +}).AddNewtonsoftJson(opts => { opts.SerializerSettings.Converters.Add(new StringEnumConverter()); - opts.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore; }); builder.Services.AddScoped(_ => LogManager.GetLogger("API")); diff --git a/API/Schema/LibraryContext/LibraryConnectors/LibraryConnector.cs b/API/Schema/LibraryContext/LibraryConnectors/LibraryConnector.cs index f332bfa..f564588 100644 --- a/API/Schema/LibraryContext/LibraryConnectors/LibraryConnector.cs +++ b/API/Schema/LibraryContext/LibraryConnectors/LibraryConnector.cs @@ -42,16 +42,15 @@ public abstract class LibraryConnector : Identifiable internal abstract Task Test(CancellationToken ct); } -[JsonConverter(typeof(StringEnumConverter))] -public enum LibraryType : byte +public enum LibraryType { /// /// /// - Komga = 0, + Komga, /// /// /// - Kavita = 1 + Kavita } \ No newline at end of file diff --git a/API/Schema/MangaContext/Manga.cs b/API/Schema/MangaContext/Manga.cs index b16ecb5..4b8cfd5 100644 --- a/API/Schema/MangaContext/Manga.cs +++ b/API/Schema/MangaContext/Manga.cs @@ -146,12 +146,11 @@ public class Manga : Identifiable public override string ToString() => $"{base.ToString()} {Name}"; } -[JsonConverter(typeof(StringEnumConverter))] -public enum MangaReleaseStatus : byte +public enum MangaReleaseStatus { - Continuing = 0, - Completed = 1, - OnHiatus = 2, - Cancelled = 3, - Unreleased = 4 + Continuing, + Completed, + OnHiatus, + Cancelled, + Unreleased } \ No newline at end of file diff --git a/API/Schema/NotificationsContext/Notification.cs b/API/Schema/NotificationsContext/Notification.cs index ae4e84e..28c26db 100644 --- a/API/Schema/NotificationsContext/Notification.cs +++ b/API/Schema/NotificationsContext/Notification.cs @@ -50,10 +50,9 @@ public class Notification : Identifiable public override string ToString() => $"{base.ToString()} {Urgency} {Title} {Message}"; } -[JsonConverter(typeof(StringEnumConverter))] -public enum NotificationUrgency : byte +public enum NotificationUrgency { - Low = 1, - Normal = 3, - High = 5 + Low, + Normal, + High } \ No newline at end of file diff --git a/API/Workers/RefreshLibrariesWorker.cs b/API/Workers/RefreshLibrariesWorker.cs index 0167afb..dbfe1c0 100644 --- a/API/Workers/RefreshLibrariesWorker.cs +++ b/API/Workers/RefreshLibrariesWorker.cs @@ -22,23 +22,22 @@ public class RefreshLibrariesWorker(IEnumerable? dependsOn = null) : } } -[JsonConverter(typeof(StringEnumConverter))] -public enum LibraryRefreshSetting : byte +public enum LibraryRefreshSetting { /// /// Refresh Libraries after all Manga are downloaded /// - AfterAllFinished = 0, + AfterAllFinished, /// /// Refresh Libraries after a Manga is downloaded /// - AfterMangaFinished = 1, + AfterMangaFinished, /// /// Refresh Libraries after every download /// - AfterEveryChapter = 2, + AfterEveryChapter, /// /// Refresh Libraries while downloading chapters, every x minutes /// - WhileDownloading = 3 + WhileDownloading } \ No newline at end of file