2024-12-14 21:53:29 +01:00
|
|
|
|
using API.Schema.Jobs;
|
|
|
|
|
using API.Schema.LibraryConnectors;
|
|
|
|
|
using API.Schema.MangaConnectors;
|
|
|
|
|
using API.Schema.NotificationConnectors;
|
|
|
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
|
|
|
|
|
|
namespace API.Schema;
|
|
|
|
|
|
|
|
|
|
public class PgsqlContext(DbContextOptions<PgsqlContext> options) : DbContext(options)
|
|
|
|
|
{
|
|
|
|
|
public DbSet<Job> Jobs { get; set; }
|
|
|
|
|
public DbSet<MangaConnector> MangaConnectors { get; set; }
|
|
|
|
|
public DbSet<Manga> Manga { get; set; }
|
|
|
|
|
public DbSet<Chapter> Chapters { get; set; }
|
|
|
|
|
public DbSet<Author> Authors { get; set; }
|
|
|
|
|
public DbSet<Link> Link { get; set; }
|
|
|
|
|
public DbSet<MangaTag> Tags { get; set; }
|
|
|
|
|
public DbSet<MangaAltTitle> AltTitles { get; set; }
|
|
|
|
|
public DbSet<LibraryConnector> LibraryConnectors { get; set; }
|
|
|
|
|
public DbSet<NotificationConnector> NotificationConnectors { get; set; }
|
2024-12-16 17:35:36 +01:00
|
|
|
|
public DbSet<Notification> Notifications { get; set; }
|
2024-12-14 21:53:29 +01:00
|
|
|
|
|
|
|
|
|
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
|
|
|
|
{
|
2024-12-16 18:28:58 +01:00
|
|
|
|
modelBuilder.Entity<MangaConnector>()
|
|
|
|
|
.HasDiscriminator(c => c.Name)
|
|
|
|
|
.HasValue<AsuraToon>("AsuraToon")
|
|
|
|
|
.HasValue<Bato>("Bato")
|
|
|
|
|
.HasValue<MangaHere>("MangaHere")
|
|
|
|
|
.HasValue<MangaKatana>("MangaKatana")
|
|
|
|
|
.HasValue<MangaLife>("Manga4Life")
|
|
|
|
|
.HasValue<Manganato>("Manganato")
|
|
|
|
|
.HasValue<Mangasee>("Mangasee")
|
|
|
|
|
.HasValue<Mangaworld>("Mangaworld")
|
|
|
|
|
.HasValue<ManhuaPlus>("ManhuaPlus")
|
|
|
|
|
.HasValue<Weebcentral>("Weebcentral")
|
|
|
|
|
.HasValue<MangaDex>("MangaDex");
|
2024-12-14 21:53:29 +01:00
|
|
|
|
modelBuilder.Entity<LibraryConnector>()
|
|
|
|
|
.HasDiscriminator<LibraryType>(l => l.LibraryType)
|
|
|
|
|
.HasValue<Komga>(LibraryType.Komga)
|
|
|
|
|
.HasValue<Kavita>(LibraryType.Kavita);
|
|
|
|
|
modelBuilder.Entity<NotificationConnector>()
|
|
|
|
|
.HasDiscriminator<NotificationConnectorType>(n => n.NotificationConnectorType)
|
|
|
|
|
.HasValue<Gotify>(NotificationConnectorType.Gotify)
|
|
|
|
|
.HasValue<Ntfy>(NotificationConnectorType.Ntfy)
|
|
|
|
|
.HasValue<Lunasea>(NotificationConnectorType.LunaSea);
|
|
|
|
|
modelBuilder.Entity<Job>()
|
|
|
|
|
.HasDiscriminator<JobType>(j => j.JobType)
|
|
|
|
|
.HasValue<MoveFileOrFolderJob>(JobType.MoveFileOrFolderJob)
|
|
|
|
|
.HasValue<DownloadNewChaptersJob>(JobType.DownloadNewChaptersJob)
|
|
|
|
|
.HasValue<DownloadSingleChapterJob>(JobType.DownloadSingleChapterJob)
|
|
|
|
|
.HasValue<UpdateMetadataJob>(JobType.UpdateMetaDataJob);
|
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Manga>()
|
2024-12-16 18:55:52 +01:00
|
|
|
|
.HasOne<MangaConnector>(m => m.MangaConnector);
|
2024-12-16 19:49:03 +01:00
|
|
|
|
modelBuilder.Entity<Manga>()
|
|
|
|
|
.Navigation(m => m.MangaConnector)
|
|
|
|
|
.AutoInclude();
|
2024-12-14 21:53:29 +01:00
|
|
|
|
modelBuilder.Entity<Manga>()
|
2024-12-16 21:52:35 +01:00
|
|
|
|
.HasMany<Author>(m => m.Authors)
|
|
|
|
|
.WithMany();
|
2024-12-16 19:49:03 +01:00
|
|
|
|
modelBuilder.Entity<Manga>()
|
|
|
|
|
.Navigation(m => m.Authors)
|
|
|
|
|
.AutoInclude();
|
2024-12-14 21:53:29 +01:00
|
|
|
|
modelBuilder.Entity<Manga>()
|
2024-12-16 21:52:35 +01:00
|
|
|
|
.HasMany<MangaTag>(m => m.Tags)
|
|
|
|
|
.WithMany();
|
2024-12-16 19:49:03 +01:00
|
|
|
|
modelBuilder.Entity<Manga>()
|
|
|
|
|
.Navigation(m => m.Tags)
|
|
|
|
|
.AutoInclude();
|
2024-12-14 21:53:29 +01:00
|
|
|
|
modelBuilder.Entity<Manga>()
|
2024-12-16 20:03:38 +01:00
|
|
|
|
.HasMany<Link>(m => m.Links)
|
|
|
|
|
.WithOne();
|
2024-12-16 19:49:03 +01:00
|
|
|
|
modelBuilder.Entity<Manga>()
|
|
|
|
|
.Navigation(m => m.Links)
|
|
|
|
|
.AutoInclude();
|
2024-12-14 21:53:29 +01:00
|
|
|
|
modelBuilder.Entity<Manga>()
|
2024-12-16 20:03:38 +01:00
|
|
|
|
.HasMany<MangaAltTitle>(m => m.AltTitles)
|
|
|
|
|
.WithOne();
|
2024-12-16 19:49:03 +01:00
|
|
|
|
modelBuilder.Entity<Manga>()
|
|
|
|
|
.Navigation(m => m.AltTitles)
|
|
|
|
|
.AutoInclude();
|
2024-12-16 20:03:38 +01:00
|
|
|
|
|
|
|
|
|
modelBuilder.Entity<Chapter>()
|
|
|
|
|
.HasOne<Manga>(c => c.ParentManga)
|
|
|
|
|
.WithMany();
|
|
|
|
|
modelBuilder.Entity<Chapter>()
|
|
|
|
|
.Navigation(c => c.ParentManga)
|
|
|
|
|
.AutoInclude();
|
2024-12-14 21:53:29 +01:00
|
|
|
|
}
|
|
|
|
|
}
|