Added Source Chapter and Source Page entities.

This commit is contained in:
2025-06-12 02:34:26 -04:00
parent 000a20bb0f
commit a82eab0ecb
18 changed files with 232 additions and 79 deletions

View File

@@ -14,9 +14,11 @@ public class MangaContext(DbContextOptions options) : DbContext(options)
public DbSet<MangaContributor> MangaContributors { get; set; }
public DbSet<Genre> Genres { get; set; }
public DbSet<MangaGenre> MangaGenres { get; set; }
public DbSet<MangaChapter> MangaChapters { get; set; }
public DbSet<ChapterSource> ChapterSources { get; set; }
public DbSet<ChapterPage> ChapterPages { get; set; }
//public DbSet<MangaChapter> MangaChapters { get; set; }
//public DbSet<ChapterSource> ChapterSources { get; set; }
//public DbSet<ChapterPage> ChapterPages { get; set; }
public DbSet<SourceChapter> SourceChapters { get; set; }
public DbSet<SourcePage> SourcePages { get; set; }
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
@@ -32,9 +34,11 @@ public class MangaContext(DbContextOptions options) : DbContext(options)
ConfigureMangaContributor(modelBuilder);
ConfigureGenre(modelBuilder);
ConfigureMangaGenre(modelBuilder);
ConfigureMangaChapter(modelBuilder);
ConfigureChapterSource(modelBuilder);
ConfigureChapterPage(modelBuilder);
//ConfigureMangaChapter(modelBuilder);
//ConfigureChapterSource(modelBuilder);
//ConfigureChapterPage(modelBuilder);
ConfigureSourceChapter(modelBuilder);
ConfigureSourcePage(modelBuilder);
}
private static void ConfigureManga(ModelBuilder modelBuilder)
@@ -152,7 +156,11 @@ public class MangaContext(DbContextOptions options) : DbContext(options)
{
modelBuilder
.Entity<MangaSource>()
.HasKey(mangaSource => new { mangaSource.MangaId, mangaSource.SourceId });
.HasKey(mangaSource => mangaSource.MangaSourceId);
//modelBuilder
// .Entity<MangaSource>()
// .HasKey(mangaSource => new { mangaSource.MangaId, mangaSource.SourceId });
modelBuilder.Entity<MangaSource>()
.HasIndex(x => x.Url)
@@ -218,50 +226,88 @@ public class MangaContext(DbContextOptions options) : DbContext(options)
.OnDelete(DeleteBehavior.Cascade);
}
private static void ConfigureMangaChapter(ModelBuilder modelBuilder)
//private static void ConfigureMangaChapter(ModelBuilder modelBuilder)
//{
// modelBuilder
// .Entity<MangaChapter>()
// .HasKey(x => x.MangaChapterId);
// modelBuilder
// .Entity<MangaChapter>()
// .HasOne(x => x.Manga)
// .WithMany(x => x.Chapters)
// .HasForeignKey(x => x.MangaId)
// .OnDelete(DeleteBehavior.Cascade);
//}
//private static void ConfigureChapterSource(ModelBuilder modelBuilder)
//{
// modelBuilder
// .Entity<ChapterSource>()
// .HasKey(chapterSource => new { chapterSource.MangaChapterId, chapterSource.SourceId });
// modelBuilder
// .Entity<ChapterSource>()
// .HasOne(x => x.Chapter)
// .WithMany(x => x.Sources)
// .HasForeignKey(x => x.MangaChapterId)
// .OnDelete(DeleteBehavior.Cascade);
//}
//private static void ConfigureChapterPage(ModelBuilder modelBuilder)
//{
// modelBuilder
// .Entity<ChapterPage>()
// .HasKey(chapterPage => chapterPage.ChapterPageId);
// modelBuilder
// .Entity<ChapterPage>()
// .HasIndex(chapterPage => new { chapterPage.MangaChapterId, chapterPage.PageNumber })
// .IsUnique(true);
// modelBuilder
// .Entity<ChapterPage>()
// .HasOne(x => x.MangaChapter)
// .WithMany(x => x.Pages)
// .HasForeignKey(x => x.MangaChapterId)
// .OnDelete(DeleteBehavior.Cascade);
//}
private static void ConfigureSourceChapter(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<MangaChapter>()
.HasKey(x => x.MangaChapterId);
.Entity<SourceChapter>()
.HasKey(sourceChapter => sourceChapter.SourceChapterId);
modelBuilder
.Entity<MangaChapter>()
.HasOne(x => x.Manga)
.WithMany(x => x.Chapters)
.HasForeignKey(x => x.MangaId)
.OnDelete(DeleteBehavior.Cascade);
}
private static void ConfigureChapterSource(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<ChapterSource>()
.HasKey(chapterSource => new { chapterSource.MangaChapterId, chapterSource.SourceId });
modelBuilder
.Entity<ChapterSource>()
.HasOne(x => x.Chapter)
.WithMany(x => x.Sources)
.HasForeignKey(x => x.MangaChapterId)
.OnDelete(DeleteBehavior.Cascade);
}
private static void ConfigureChapterPage(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<ChapterPage>()
.HasKey(chapterPage => chapterPage.ChapterPageId);
modelBuilder
.Entity<ChapterPage>()
.HasIndex(chapterPage => new { chapterPage.MangaChapterId, chapterPage.PageNumber })
.Entity<SourceChapter>()
.HasIndex(sourceChapter => new { sourceChapter.MangaSourceId, sourceChapter.ChapterNumber, sourceChapter.Url })
.IsUnique(true);
modelBuilder
.Entity<ChapterPage>()
.HasOne(x => x.MangaChapter)
.Entity<SourceChapter>()
.HasOne(x => x.MangaSource)
.WithMany(x => x.Chapters)
.HasForeignKey(x => x.MangaSourceId)
.OnDelete(DeleteBehavior.Cascade);
}
private static void ConfigureSourcePage(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<SourcePage>()
.HasKey(sourcePage => sourcePage.SourcePageId);
modelBuilder
.Entity<SourcePage>()
.HasIndex(sourcePage => new { sourcePage.SourceChapterId, sourcePage.PageNumber })
.IsUnique(true);
modelBuilder
.Entity<SourcePage>()
.HasOne(x => x.Chapter)
.WithMany(x => x.Pages)
.HasForeignKey(x => x.MangaChapterId)
.HasForeignKey(x => x.SourceChapterId)
.OnDelete(DeleteBehavior.Cascade);
}
}