Added contributor classes for manga. Implemented MangaDex search.

This commit is contained in:
2025-05-24 15:56:44 -04:00
parent f760cff21f
commit 1a752bb57e
20 changed files with 706 additions and 24 deletions

View File

@@ -0,0 +1,9 @@
namespace MangaReader.Core.Data;
public class Contributor
{
public int ContributorId { get; set; }
public required string Name { get; set; }
public ICollection<MangaContributor> MangaContributions { get; set; } = [];
}

View File

@@ -7,18 +7,10 @@ public class Manga
public required string Title { get; set; }
public string? Description { get; set; }
public virtual ICollection<MangaCover> Covers { get; set; }
public virtual ICollection<MangaTitle> Titles { get; set; }
public virtual ICollection<MangaSource> Sources { get; set; }
public virtual ICollection<MangaGenre> Genres { get; set; }
public virtual ICollection<MangaChapter> Chapters { get; set; }
public Manga()
{
Covers = new HashSet<MangaCover>();
Titles = new HashSet<MangaTitle>();
Sources = new HashSet<MangaSource>();
Genres = new HashSet<MangaGenre>();
Chapters = new HashSet<MangaChapter>();
}
public virtual ICollection<MangaCover> Covers { get; set; } = [];
public virtual ICollection<MangaTitle> Titles { get; set; } = [];
public virtual ICollection<MangaSource> Sources { get; set; } = [];
public virtual ICollection<MangaContributor> Contributors { get; set; } = [];
public virtual ICollection<MangaGenre> Genres { get; set; } = [];
public virtual ICollection<MangaChapter> Chapters { get; set; } = [];
}

View File

@@ -9,6 +9,8 @@ public class MangaContext(DbContextOptions options) : DbContext(options)
public DbSet<MangaTitle> MangaTitles { get; set; }
public DbSet<Source> Sources { get; set; }
public DbSet<MangaSource> MangaSources { get; set; }
public DbSet<Contributor> Contributors { get; set; }
public DbSet<MangaContributor> MangaContributors { get; set; }
public DbSet<Genre> Genres { get; set; }
public DbSet<MangaGenre> MangaGenres { get; set; }
public DbSet<MangaChapter> MangaChapters { get; set; }
@@ -24,6 +26,8 @@ public class MangaContext(DbContextOptions options) : DbContext(options)
ConfigureMangaTitle(modelBuilder);
ConfigureSource(modelBuilder);
ConfigureMangaSource(modelBuilder);
ConfigureContributor(modelBuilder);
ConfigureMangaContributor(modelBuilder);
ConfigureGenre(modelBuilder);
ConfigureMangaGenre(modelBuilder);
ConfigureMangaChapter(modelBuilder);
@@ -37,6 +41,10 @@ public class MangaContext(DbContextOptions options) : DbContext(options)
.Entity<Manga>()
.HasKey(x => x.MangaId);
modelBuilder.Entity<Manga>()
.HasIndex(x => x.Title)
.IsUnique();
modelBuilder.Entity<Manga>()
.HasIndex(x => x.Slug)
.IsUnique();
@@ -118,6 +126,32 @@ public class MangaContext(DbContextOptions options) : DbContext(options)
.OnDelete(DeleteBehavior.Cascade);
}
private static void ConfigureContributor(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<Contributor>()
.HasKey(x => x.ContributorId);
modelBuilder
.Entity<Contributor>()
.HasIndex(x => x.Name)
.IsUnique(true);
}
private static void ConfigureMangaContributor(ModelBuilder modelBuilder)
{
modelBuilder
.Entity<MangaContributor>()
.HasKey(mc => new { mc.MangaId, mc.ContributorId, mc.Role });
modelBuilder
.Entity<MangaContributor>()
.HasOne(x => x.Manga)
.WithMany(x => x.Contributors)
.HasForeignKey(x => x.MangaId)
.OnDelete(DeleteBehavior.Cascade);
}
private static void ConfigureGenre(ModelBuilder modelBuilder)
{
modelBuilder

View File

@@ -0,0 +1,12 @@
namespace MangaReader.Core.Data;
public class MangaContributor
{
public int MangaId { get; set; }
public required Manga Manga { get; set; }
public int ContributorId { get; set; }
public required Contributor Contributor { get; set; }
public MangaContributorRole Role { get; set; }
}

View File

@@ -0,0 +1,7 @@
namespace MangaReader.Core.Data;
public enum MangaContributorRole
{
Author,
Artist
}