mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-03 04:11:10 +00:00
Implements first stage library management system
This commit is contained in:
1 parent
5e0f94cd82
commit
36352ea9e8
291 files changed
+3733
-1384
No files matched your search
@@ -1,8 +1,9 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Entities.Common;
|
||||
using Lumina.Contracts.Entities.WrittenContentLibrary.BookLibrary;
|
||||
using Lumina.Contracts.Entities.MediaLibrary.WrittenContentLibrary.BookLibrary;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
#endregion
|
||||
|
||||
@@ -25,63 +26,114 @@ public class BookConfiguration : IEntityTypeConfiguration<BookEntity>
|
||||
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
|
||||
.HasColumnOrder(0);
|
||||
|
||||
builder.Property(book => book.Title).IsRequired().HasMaxLength(255).HasColumnOrder(1);
|
||||
builder.Property(book => book.OriginalTitle).HasMaxLength(255).HasColumnOrder(2);
|
||||
builder.Property(book => book.Description).HasMaxLength(2000).HasColumnOrder(3);
|
||||
builder.Property(book => book.OriginalReleaseDate).HasColumnOrder(4);
|
||||
builder.Property(book => book.OriginalReleaseYear).HasColumnOrder(5);
|
||||
builder.Property(book => book.ReReleaseDate).HasColumnOrder(6);
|
||||
builder.Property(book => book.ReReleaseYear).HasColumnOrder(7);
|
||||
builder.Property(book => book.ReleaseCountry).HasColumnOrder(8);
|
||||
builder.Property(book => book.ReleaseVersion).HasColumnOrder(9);
|
||||
builder.Property(book => book.LanguageCode).HasColumnOrder(10);
|
||||
builder.Property(book => book.LanguageName).HasColumnOrder(11);
|
||||
builder.Property(book => book.LanguageNativeName).HasColumnOrder(12);
|
||||
builder.Property(book => book.OriginalLanguageCode).HasColumnOrder(13);
|
||||
builder.Property(book => book.OriginalLanguageName).HasColumnOrder(14);
|
||||
builder.Property(book => book.OriginalLanguageNativeName).HasColumnOrder(15);
|
||||
builder.Property(book => book.Title)
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnOrder(1);
|
||||
builder.Property(book => book.OriginalTitle)
|
||||
.HasMaxLength(255)
|
||||
.HasColumnOrder(2);
|
||||
builder.Property(book => book.Description)
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnOrder(3);
|
||||
builder.Property(book => book.OriginalReleaseDate)
|
||||
.HasColumnOrder(4);
|
||||
builder.Property(book => book.OriginalReleaseYear)
|
||||
.HasColumnOrder(5);
|
||||
builder.Property(book => book.ReReleaseDate)
|
||||
.HasColumnOrder(6);
|
||||
builder.Property(book => book.ReReleaseYear)
|
||||
.HasColumnOrder(7);
|
||||
builder.Property(book => book.ReleaseCountry)
|
||||
.HasColumnOrder(8);
|
||||
builder.Property(book => book.ReleaseVersion)
|
||||
.HasColumnOrder(9);
|
||||
builder.Property(book => book.LanguageCode)
|
||||
.HasColumnOrder(10);
|
||||
builder.Property(book => book.LanguageName)
|
||||
.HasColumnOrder(11);
|
||||
builder.Property(book => book.LanguageNativeName)
|
||||
.HasColumnOrder(12);
|
||||
builder.Property(book => book.OriginalLanguageCode)
|
||||
.HasColumnOrder(13);
|
||||
builder.Property(book => book.OriginalLanguageName)
|
||||
.HasColumnOrder(14);
|
||||
builder.Property(book => book.OriginalLanguageNativeName)
|
||||
.HasColumnOrder(15);
|
||||
// since Tag is a Domain ValueObject (no identity), but we also don't want to have duplicates,
|
||||
// we need to configure it as a many-to-many relationship, where the tag itself is the primary key
|
||||
builder.HasMany(book => book.Tags)
|
||||
.WithMany()
|
||||
.UsingEntity<Dictionary<string, object>>(
|
||||
"BookTags",
|
||||
j => j.HasOne<TagEntity>().WithMany().HasForeignKey("TagId"),
|
||||
j => j.HasOne<BookEntity>().WithMany().HasForeignKey("BookId"),
|
||||
j =>
|
||||
{
|
||||
j.HasKey("BookId", "TagId");
|
||||
j.ToTable("BookTags");
|
||||
});
|
||||
.WithMany()
|
||||
.UsingEntity<Dictionary<string, object>>(
|
||||
"BookTags",
|
||||
j => j.HasOne<TagEntity>()
|
||||
.WithMany()
|
||||
.HasForeignKey("TagId"),
|
||||
j => j.HasOne<BookEntity>()
|
||||
.WithMany()
|
||||
.HasForeignKey("BookId"),
|
||||
j =>
|
||||
{
|
||||
j.HasKey("BookId", "TagId");
|
||||
j.ToTable("BookTags");
|
||||
});
|
||||
|
||||
builder.HasMany(book => book.Genres)
|
||||
.WithMany()
|
||||
.UsingEntity<Dictionary<string, object>>(
|
||||
"BookGenres",
|
||||
j => j.HasOne<GenreEntity>().WithMany().HasForeignKey("GenreId"),
|
||||
j => j.HasOne<BookEntity>().WithMany().HasForeignKey("BookId"),
|
||||
j =>
|
||||
{
|
||||
j.HasKey("BookId", "GenreId");
|
||||
j.ToTable("BookGenres");
|
||||
});
|
||||
.WithMany()
|
||||
.UsingEntity<Dictionary<string, object>>(
|
||||
"BookGenres",
|
||||
j => j.HasOne<GenreEntity>()
|
||||
.WithMany()
|
||||
.HasForeignKey("GenreId"),
|
||||
j => j.HasOne<BookEntity>()
|
||||
.WithMany()
|
||||
.HasForeignKey("BookId"),
|
||||
j =>
|
||||
{
|
||||
j.HasKey("BookId", "GenreId");
|
||||
j.ToTable("BookGenres");
|
||||
});
|
||||
|
||||
builder.Property(book => book.Publisher).HasMaxLength(100).HasColumnOrder(16);
|
||||
builder.Property(book => book.PageCount).HasColumnOrder(17);
|
||||
builder.Property(book => book.Format).HasColumnOrder(18);
|
||||
builder.Property(book => book.Edition).HasMaxLength(50).HasColumnOrder(19);
|
||||
builder.Property(book => book.VolumeNumber).HasColumnOrder(20);
|
||||
builder.Property(book => book.ASIN).HasMaxLength(10).HasColumnOrder(21);
|
||||
builder.Property(book => book.GoodreadsId).HasColumnOrder(22);
|
||||
builder.Property(book => book.LCCN).HasColumnOrder(23);
|
||||
builder.Property(book => book.OCLCNumber).HasColumnOrder(24);
|
||||
builder.Property(book => book.OpenLibraryId).HasMaxLength(50).HasColumnOrder(25);
|
||||
builder.Property(book => book.LibraryThingId).HasMaxLength(50).HasColumnOrder(26);
|
||||
builder.Property(book => book.GoogleBooksId).HasMaxLength(12).HasColumnOrder(27);
|
||||
builder.Property(book => book.BarnesAndNobleId).HasMaxLength(10).HasColumnOrder(28);
|
||||
builder.Property(book => book.AppleBooksId).HasColumnOrder(29);
|
||||
builder.Property(book => book.Created).HasColumnOrder(30);
|
||||
builder.Property(book => book.Updated).HasColumnOrder(31);
|
||||
builder.Property(book => book.Publisher)
|
||||
.HasMaxLength(100)
|
||||
.HasColumnOrder(16);
|
||||
builder.Property(book => book.PageCount)
|
||||
.HasColumnOrder(17);
|
||||
builder.Property(book => book.Format)
|
||||
.HasConversion<string>()
|
||||
.HasColumnOrder(18);
|
||||
builder.Property(book => book.Edition)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnOrder(19);
|
||||
builder.Property(book => book.VolumeNumber)
|
||||
.HasColumnOrder(20);
|
||||
builder.Property(book => book.ASIN)
|
||||
.HasMaxLength(10)
|
||||
.HasColumnOrder(21);
|
||||
builder.Property(book => book.GoodreadsId)
|
||||
.HasColumnOrder(22);
|
||||
builder.Property(book => book.LCCN)
|
||||
.HasColumnOrder(23);
|
||||
builder.Property(book => book.OCLCNumber)
|
||||
.HasColumnOrder(24);
|
||||
builder.Property(book => book.OpenLibraryId)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnOrder(25);
|
||||
builder.Property(book => book.LibraryThingId)
|
||||
.HasMaxLength(50)
|
||||
.HasColumnOrder(26);
|
||||
builder.Property(book => book.GoogleBooksId)
|
||||
.HasMaxLength(12)
|
||||
.HasColumnOrder(27);
|
||||
builder.Property(book => book.BarnesAndNobleId)
|
||||
.HasMaxLength(10)
|
||||
.HasColumnOrder(28);
|
||||
builder.Property(book => book.AppleBooksId)
|
||||
.HasColumnOrder(29);
|
||||
builder.Property(book => book.Created)
|
||||
.HasColumnOrder(30);
|
||||
builder.Property(book => book.Updated)
|
||||
.HasColumnOrder(31);
|
||||
|
||||
//builder.HasMany<ContributorIdModel>()
|
||||
//.WithMany()
|
||||
@@ -108,8 +160,10 @@ public class BookConfiguration : IEntityTypeConfiguration<BookEntity>
|
||||
builder.OwnsMany(book => book.Ratings, ratingBuilder =>
|
||||
{
|
||||
ratingBuilder.ToTable("BookRatings");
|
||||
ratingBuilder.WithOwner().HasForeignKey("BookId");
|
||||
ratingBuilder.Property<int>("Id").ValueGeneratedOnAdd();
|
||||
ratingBuilder.WithOwner()
|
||||
.HasForeignKey("BookId");
|
||||
ratingBuilder.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
ratingBuilder.HasKey("Id");
|
||||
|
||||
ratingBuilder.Property(rating => rating.Value)
|
||||
@@ -132,8 +186,10 @@ public class BookConfiguration : IEntityTypeConfiguration<BookEntity>
|
||||
builder.OwnsMany(book => book.ISBNs, isbnBuilder =>
|
||||
{
|
||||
isbnBuilder.ToTable("BookISBNs");
|
||||
isbnBuilder.WithOwner().HasForeignKey("BookId");
|
||||
isbnBuilder.Property<int>("Id").ValueGeneratedOnAdd();
|
||||
isbnBuilder.WithOwner()
|
||||
.HasForeignKey("BookId");
|
||||
isbnBuilder.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
isbnBuilder.HasKey("Id");
|
||||
|
||||
isbnBuilder.Property(isbn => isbn.Value)
|
||||
@@ -157,4 +213,4 @@ public class BookConfiguration : IEntityTypeConfiguration<BookEntity>
|
||||
// builder.HasKey(c => c.Id);
|
||||
// builder.Property(c => c.Id).ValueGeneratedNever();
|
||||
// }
|
||||
//}
|
||||
//}
|
||||
@@ -0,0 +1,60 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Contracts.Entities.MediaLibrary.Management;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using System;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Common.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Configures the entity mapping for the <see cref="LibraryEntity"/> entity.
|
||||
/// </summary>
|
||||
public class LibraryConfiguration : IEntityTypeConfiguration<LibraryEntity>
|
||||
{
|
||||
/// <summary>
|
||||
/// Configures the <see cref="LibraryEntity"/> entity.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder to be used to configure the entity.</param>
|
||||
public void Configure(EntityTypeBuilder<LibraryEntity> builder)
|
||||
{
|
||||
builder.ToTable("Libraries");
|
||||
builder.HasKey(library => library.Id);
|
||||
builder.Property(library => library.Id)
|
||||
.ValueGeneratedNever() // because EF always tries to generate the value for the Id, and because we generate it as part of the aggregate root, we need to tell EF not to generate it
|
||||
.HasColumnOrder(0);
|
||||
|
||||
builder.Property(library => library.Title)
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnOrder(1);
|
||||
|
||||
builder.Property(library => library.LibraryType)
|
||||
.IsRequired()
|
||||
.HasConversion<string>()
|
||||
.HasColumnOrder(2);
|
||||
|
||||
// one user with many libraries
|
||||
builder.HasOne(library => library.User)
|
||||
.WithMany(user => user.Libraries)
|
||||
.HasForeignKey(library => library.UserId)
|
||||
.IsRequired();
|
||||
|
||||
// using OwnsMany because paths are domain Value Objects, thus they have no independent identity, and their lifecycle is bound to the Library
|
||||
builder.OwnsMany(library => library.ContentLocations, contentLocationBuilder =>
|
||||
{
|
||||
contentLocationBuilder.ToTable("LibraryContentLocations");
|
||||
contentLocationBuilder.WithOwner()
|
||||
.HasForeignKey("LibraryId");
|
||||
|
||||
contentLocationBuilder.Property<Guid>("Id")
|
||||
.ValueGeneratedOnAdd();
|
||||
contentLocationBuilder.HasKey("Id");
|
||||
|
||||
contentLocationBuilder.Property(location => location.Path)
|
||||
.HasColumnName("Path")
|
||||
.HasMaxLength(260)
|
||||
.IsRequired();
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -40,5 +40,11 @@ public class UserConfiguration : IEntityTypeConfiguration<UserEntity>
|
||||
|
||||
builder.Property(user => user.VerificationTokenCreated)
|
||||
.HasColumnOrder(5);
|
||||
|
||||
builder.HasMany(user => user.Libraries)
|
||||
.WithOne(library => library.User)
|
||||
.HasForeignKey(library => library.UserId)
|
||||
.IsRequired() // a library must have a user
|
||||
.OnDelete(DeleteBehavior.Cascade);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user