mirror of
https://github.com/BinaryAlley/Nemera.git
synced 2026-12-02 20:11:10 +00:00
Implements Data Access Layer
This commit is contained in:
1 parent
b69e59a3d8
commit
8b729cc16c
24 files changed
+1721
-9
No files matched your search
@@ -0,0 +1,16 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.Application.Common.Models.Books;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for the repository for books.
|
||||
/// </summary>
|
||||
public interface IBookRepository : IRepository<BookDto>,
|
||||
IInsertRepositoryAction<BookDto>,
|
||||
IGetAllRepositoryAction<BookDto>
|
||||
{
|
||||
}
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "delete all" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
public interface IDeleteAllRepositoryAction
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Deletes all entities from the storage medium.
|
||||
/// </summary>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
|
||||
Task<ErrorOr<Deleted>> DeleteAllAsync();
|
||||
#endregion
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "delete by id" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TId">The type used for the identifier of the respository. It should not be <see langword="null"/>.</typeparam>
|
||||
public interface IDeleteByIdRepositoryAction<TId> where TId : notnull
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Deletes an element identified by <paramref name="id"/> from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the element to be deleted.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
|
||||
Task<ErrorOr<Deleted>> DeleteByIdAsync(TId id, CancellationToken cancellationToken);
|
||||
#endregion
|
||||
}
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "get all" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type used as a result for the "get all" action. It should implement <see cref="IStorageEntity"/>.</typeparam>
|
||||
public interface IGetAllRepositoryAction<TModel> where TModel : IStorageEntity
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Gets all data of type <typeparamref name="TModel"/> from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> containing either a collection of <typeparamref name="TModel"/>, or an error.</returns>
|
||||
Task<ErrorOr<IEnumerable<TModel>>> GetAllAsync(CancellationToken cancellationToken);
|
||||
#endregion
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "get by id" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type used as a result for the "get by id" action. It should implement <see cref="IStorageEntity"/>.</typeparam>
|
||||
/// <typeparam name="TId">The type used for the identifier of the respository. It should not be <see langword="null"/>.</typeparam>
|
||||
public interface IGetByIdRepositoryAction<TModel, TId> where TModel : IStorageEntity
|
||||
where TId : notnull
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Gets an element of type <typeparamref name="TModel"/> identified by <paramref name="id"/> from the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="id">The id of the element to get.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> containing either a <typeparamref name="TModel"/> identified by <paramref name="id"/>, or an error.</returns>
|
||||
Task<ErrorOr<TModel?>> GetByIdAsync(TId id, CancellationToken cancellationToken);
|
||||
#endregion
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "insert" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type used for the insert action. It should implement <see cref="IStorageEntity"/>.</typeparam>
|
||||
public interface IInsertRepositoryAction<TModel> where TModel : IStorageEntity
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Saves an element of type <typeparamref name="TModel"/> in the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="data">The element to be saved.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
|
||||
Task<ErrorOr<Created>> InsertAsync(TModel data, CancellationToken cancellationToken);
|
||||
#endregion
|
||||
}
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Actions;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining the "update" action for interacting with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type used for the update action. It should implement <see cref="IStorageEntity"/>.</typeparam>
|
||||
public interface IUpdateRepositoryAction<TModel> where TModel : IStorageEntity
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Updates <paramref name="data"/> in the storage medium.
|
||||
/// </summary>
|
||||
/// <param name="data">The element that will be updated.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
|
||||
Task<ErrorOr<Updated>> UpdateAsync(TModel data, CancellationToken cancellationToken);
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for interaction with a generic persistance medium.
|
||||
/// </summary>
|
||||
/// <typeparam name="TModel">The type used for the repository. It should implement <see cref="IStorageEntity"/>.</typeparam>
|
||||
public interface IRepository<TModel> where TModel : IStorageEntity
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
namespace Lumina.Application.Common.DataAccess.UoW;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction boundary with the Data Access Layer.
|
||||
/// </summary>
|
||||
public interface IUnitOfWork
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Exposes a repository of type <typeparamref name="TRepository"/> to the Business Layer.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRepository">The type of the exposed repository.</typeparam>
|
||||
/// <returns>A repository of type <typeparamref name="TRepository"/>.</returns>
|
||||
TRepository GetRepository<TRepository>();
|
||||
|
||||
/// <summary>
|
||||
/// Saves all changes made to the database.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
Task SaveChangesAsync(CancellationToken cancellationToken);
|
||||
|
||||
/// <summary>
|
||||
/// Opens a transaction.
|
||||
/// </summary>
|
||||
void OpenTransaction();
|
||||
|
||||
/// <summary>
|
||||
/// Commits a transaction.
|
||||
/// </summary>
|
||||
void CommitTransaction();
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Lumina.Application.Common.Models.Common;
|
||||
|
||||
/// <summary>
|
||||
/// Interface for storage DTOs, enforces Id.
|
||||
/// </summary>
|
||||
public interface IStorageEntity
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
/// <summary>
|
||||
/// Gets or sets the identifier of the entity.
|
||||
/// </summary>
|
||||
Guid Id { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// The time and date when the entity was added.
|
||||
/// </summary>
|
||||
DateTime Created { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The time and date when the entity was updated.
|
||||
/// </summary>
|
||||
DateTime? Updated { get; set; }
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,181 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Models.Books;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
using Lumina.Domain.Core.Aggregates.WrittenContentLibrary.BookLibraryAggregate;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Common.Configuration;
|
||||
|
||||
/// <summary>
|
||||
/// Configures the entity mapping for the <see cref="BookDto"/> aggregate root.
|
||||
/// </summary>
|
||||
public class BookConfiguration : IEntityTypeConfiguration<BookDto>
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Configures the <see cref="Book"/> entity.
|
||||
/// </summary>
|
||||
/// <param name="builder">The builder to be used to configure the entity.</param>
|
||||
public void Configure(EntityTypeBuilder<BookDto> builder)
|
||||
{
|
||||
builder.ToTable("Books");
|
||||
builder.HasKey(book => book.Id);
|
||||
builder.Property(book => book.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(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), we need to configure it as a many-to-many relationship
|
||||
builder.HasMany(book => book.Tags)
|
||||
.WithMany()
|
||||
.UsingEntity<Dictionary<string, object>>(
|
||||
"BookTags",
|
||||
j => j.HasOne<TagDto>().WithMany().HasForeignKey("TagId"),
|
||||
j => j.HasOne<BookDto>().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<GenreDto>().WithMany().HasForeignKey("GenreId"),
|
||||
j => j.HasOne<BookDto>().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.HasMany<ContributorIdDto>()
|
||||
//.WithMany()
|
||||
//.UsingEntity<Dictionary<string, object>>(
|
||||
// "BookContributors",
|
||||
// j => j.HasOne<ContributorIdDto>().WithMany().HasForeignKey("ContributorId"),
|
||||
// j => j.HasOne<BookDto>().WithMany().HasForeignKey("BookId"),
|
||||
// j =>
|
||||
// {
|
||||
// j.HasKey("BookId", "ContributorId");
|
||||
// j.ToTable("BookContributors");
|
||||
// });
|
||||
|
||||
//builder.OwnsMany(book => book.ContributorIds, ownedBuilder =>
|
||||
//{
|
||||
// ownedBuilder.ToTable("BookContributors");
|
||||
// ownedBuilder.WithOwner().HasForeignKey("BookId");
|
||||
// ownedBuilder.Property(c => c.Id)
|
||||
// .HasColumnName("ContributorId")
|
||||
// .HasColumnType("uniqueidentifier");
|
||||
// ownedBuilder.HasKey("BookId", "Id"); // Use the actual property name 'Id' here
|
||||
//});
|
||||
|
||||
builder.OwnsMany(book => book.Ratings, ratingBuilder =>
|
||||
{
|
||||
ratingBuilder.ToTable("BookRatings");
|
||||
ratingBuilder.WithOwner().HasForeignKey("BookId");
|
||||
ratingBuilder.Property<int>("Id").ValueGeneratedOnAdd();
|
||||
ratingBuilder.HasKey("Id");
|
||||
|
||||
ratingBuilder.Property(r => r.Value)
|
||||
.HasColumnType("decimal(3,2)")
|
||||
.IsRequired();
|
||||
|
||||
ratingBuilder.Property(r => r.MaxValue)
|
||||
.HasColumnType("decimal(3,2)")
|
||||
.IsRequired();
|
||||
|
||||
ratingBuilder.Property(r => r.VoteCount)
|
||||
.IsRequired(false);
|
||||
|
||||
ratingBuilder.Property(r => r.Source)
|
||||
.HasConversion<string>()
|
||||
.HasMaxLength(50)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
builder.OwnsMany(book => book.ISBNs, isbnBuilder =>
|
||||
{
|
||||
isbnBuilder.ToTable("BookISBNs");
|
||||
isbnBuilder.WithOwner().HasForeignKey("BookId");
|
||||
isbnBuilder.Property<int>("Id").ValueGeneratedOnAdd();
|
||||
isbnBuilder.HasKey("Id");
|
||||
|
||||
isbnBuilder.Property(isbn => isbn.Value)
|
||||
.HasColumnName("ISBN")
|
||||
.HasMaxLength(13)
|
||||
.IsRequired();
|
||||
|
||||
isbnBuilder.Property(isbn => isbn.Format)
|
||||
.HasConversion<string>()
|
||||
.HasMaxLength(6)
|
||||
.IsRequired();
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class TagConfiguration : IEntityTypeConfiguration<TagDto>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<TagDto> builder)
|
||||
{
|
||||
builder.ToTable("Tags");
|
||||
builder.HasKey(t => t.Name);
|
||||
builder.Property(t => t.Name).IsRequired().HasMaxLength(50);
|
||||
}
|
||||
}
|
||||
|
||||
public class GenreConfiguration : IEntityTypeConfiguration<GenreDto>
|
||||
{
|
||||
public void Configure(EntityTypeBuilder<GenreDto> builder)
|
||||
{
|
||||
builder.ToTable("Genres");
|
||||
builder.HasKey(g => g.Name);
|
||||
builder.Property(g => g.Name).IsRequired().HasMaxLength(50);
|
||||
}
|
||||
}
|
||||
|
||||
//public class ContributorConfiguration : IEntityTypeConfiguration<ContributorIdDto>
|
||||
//{
|
||||
// public void Configure(EntityTypeBuilder<ContributorIdDto> builder)
|
||||
// {
|
||||
// builder.ToTable("Contributors");
|
||||
// builder.HasKey(c => c.Id);
|
||||
// builder.Property(c => c.Id).ValueGeneratedNever();
|
||||
// }
|
||||
//}
|
||||
@@ -0,0 +1,58 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using System.Reflection;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.DataAccess.Core.Repositories.Common.Factory;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Common.DependencyInjection;
|
||||
|
||||
/// <summary>
|
||||
/// Contains all services of the DataAccess layer.
|
||||
/// </summary>
|
||||
public static class DataAccessLayerServices
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Extension method for adding the DataAccess layer services to the DI container.
|
||||
/// </summary>
|
||||
/// <param name="services">The service collection to add the services to.</param>
|
||||
/// <returns>The updated <see cref="IServiceCollection"/>.</returns>
|
||||
public static void AddDataAccessLayerServices(this IServiceCollection services)
|
||||
{
|
||||
var basePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
|
||||
if (!Directory.Exists(basePath))
|
||||
throw new DirectoryNotFoundException($"The base path '{basePath}' does not exist.");
|
||||
services.AddDbContext<LuminaDbContext>(options =>
|
||||
{
|
||||
options.UseSqlite($"Data Source={Path.Combine(basePath, "Lumina.db")}");
|
||||
});
|
||||
|
||||
services.AddScoped<IUnitOfWork, UnitOfWork>();
|
||||
|
||||
Type[]? dataAccessLayerTypes = Assembly.GetExecutingAssembly().GetTypes();
|
||||
Type? genericRepositoryType = typeof(IRepository<>);
|
||||
Type? repositoryFactoryType = typeof(RepositoryFactory);
|
||||
Type? iRepositoryFactoryType = typeof(IRepositoryFactory);
|
||||
|
||||
services.AddScoped(iRepositoryFactoryType!, repositoryFactoryType!);
|
||||
|
||||
// get all classes implementing IRepository (all repository classes) and register them as their corresponding repository interface
|
||||
IEnumerable<Type> repositoryTypes = dataAccessLayerTypes.Where(t => !t.IsInterface &&
|
||||
t.GetInterfaces()
|
||||
.Any(i => i.IsGenericType &&
|
||||
i.GetGenericTypeDefinition() == genericRepositoryType));
|
||||
foreach (Type type in repositoryTypes)
|
||||
{
|
||||
services.AddScoped(type.GetInterfaces() // TODO: change to scoped when DbContext is implemented
|
||||
.Where(i => !i.IsGenericType &&
|
||||
i.GetInterfaces()
|
||||
.Any(j => j.GetGenericTypeDefinition() == genericRepositoryType))
|
||||
.First(), type);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
+324
@@ -0,0 +1,324 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Lumina.DataAccess.Common.Migrations
|
||||
{
|
||||
[DbContext(typeof(LuminaDbContext))]
|
||||
[Migration("20240826201057_InitialMigration")]
|
||||
partial class InitialMigration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.8");
|
||||
|
||||
modelBuilder.Entity("BookGenres", b =>
|
||||
{
|
||||
b.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("GenreId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("BookId", "GenreId");
|
||||
|
||||
b.HasIndex("GenreId");
|
||||
|
||||
b.ToTable("BookGenres", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookTags", b =>
|
||||
{
|
||||
b.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("TagId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("BookId", "TagId");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("BookTags", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(0);
|
||||
|
||||
b.Property<string>("ASIN")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(21);
|
||||
|
||||
b.Property<string>("AppleBooksId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(29);
|
||||
|
||||
b.Property<string>("BarnesAndNobleId")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(28);
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(30);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.Property<string>("Edition")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(19);
|
||||
|
||||
b.Property<string>("Format")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(18);
|
||||
|
||||
b.Property<string>("GoodreadsId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(22);
|
||||
|
||||
b.Property<string>("GoogleBooksId")
|
||||
.HasMaxLength(12)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(27);
|
||||
|
||||
b.Property<string>("LCCN")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(23);
|
||||
|
||||
b.Property<string>("LanguageCode")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(10);
|
||||
|
||||
b.Property<string>("LanguageName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(11);
|
||||
|
||||
b.Property<string>("LanguageNativeName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(12);
|
||||
|
||||
b.Property<string>("LibraryThingId")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(26);
|
||||
|
||||
b.Property<string>("OCLCNumber")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(24);
|
||||
|
||||
b.Property<string>("OpenLibraryId")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(25);
|
||||
|
||||
b.Property<string>("OriginalLanguageCode")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(13);
|
||||
|
||||
b.Property<string>("OriginalLanguageName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(14);
|
||||
|
||||
b.Property<string>("OriginalLanguageNativeName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(15);
|
||||
|
||||
b.Property<DateOnly?>("OriginalReleaseDate")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<int?>("OriginalReleaseYear")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(5);
|
||||
|
||||
b.Property<string>("OriginalTitle")
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(2);
|
||||
|
||||
b.Property<int?>("PageCount")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(17);
|
||||
|
||||
b.Property<string>("Publisher")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(16);
|
||||
|
||||
b.Property<DateOnly?>("ReReleaseDate")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(6);
|
||||
|
||||
b.Property<int?>("ReReleaseYear")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(7);
|
||||
|
||||
b.Property<string>("ReleaseCountry")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(8);
|
||||
|
||||
b.Property<string>("ReleaseVersion")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(9);
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<DateTime?>("Updated")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(31);
|
||||
|
||||
b.Property<int?>("VolumeNumber")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(20);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Books", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreDto", b =>
|
||||
{
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Name");
|
||||
|
||||
b.ToTable("Genres", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagDto", b =>
|
||||
{
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Name");
|
||||
|
||||
b.ToTable("Tags", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookGenres", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("BookId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.Models.Common.GenreDto", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("GenreId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookTags", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("BookId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.Models.Common.TagDto", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
|
||||
{
|
||||
b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingDto", "Ratings", b1 =>
|
||||
{
|
||||
b1.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b1.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<decimal>("MaxValue")
|
||||
.HasColumnType("decimal(3,2)");
|
||||
|
||||
b1.Property<string>("Source")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<decimal>("Value")
|
||||
.HasColumnType("decimal(3,2)");
|
||||
|
||||
b1.Property<int?>("VoteCount")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b1.HasKey("Id");
|
||||
|
||||
b1.HasIndex("BookId");
|
||||
|
||||
b1.ToTable("BookRatings", (string)null);
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("BookId");
|
||||
});
|
||||
|
||||
b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnDto", "ISBNs", b1 =>
|
||||
{
|
||||
b1.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b1.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<string>("Format")
|
||||
.IsRequired()
|
||||
.HasMaxLength(6)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(13)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("ISBN");
|
||||
|
||||
b1.HasKey("Id");
|
||||
|
||||
b1.HasIndex("BookId");
|
||||
|
||||
b1.ToTable("BookISBNs", (string)null);
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("BookId");
|
||||
});
|
||||
|
||||
b.Navigation("ISBNs");
|
||||
|
||||
b.Navigation("Ratings");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
using System;
|
||||
using Microsoft.EntityFrameworkCore.Migrations;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Lumina.DataAccess.Common.Migrations
|
||||
{
|
||||
/// <inheritdoc />
|
||||
public partial class InitialMigration : Migration
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected override void Up(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Books",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Title = table.Column<string>(type: "TEXT", maxLength: 255, nullable: false),
|
||||
OriginalTitle = table.Column<string>(type: "TEXT", maxLength: 255, nullable: true),
|
||||
Description = table.Column<string>(type: "TEXT", maxLength: 2000, nullable: true),
|
||||
OriginalReleaseDate = table.Column<DateOnly>(type: "TEXT", nullable: true),
|
||||
OriginalReleaseYear = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
ReReleaseDate = table.Column<DateOnly>(type: "TEXT", nullable: true),
|
||||
ReReleaseYear = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
ReleaseCountry = table.Column<string>(type: "TEXT", nullable: true),
|
||||
ReleaseVersion = table.Column<string>(type: "TEXT", nullable: true),
|
||||
LanguageCode = table.Column<string>(type: "TEXT", nullable: true),
|
||||
LanguageName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
LanguageNativeName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OriginalLanguageCode = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OriginalLanguageName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OriginalLanguageNativeName = table.Column<string>(type: "TEXT", nullable: true),
|
||||
Publisher = table.Column<string>(type: "TEXT", maxLength: 100, nullable: true),
|
||||
PageCount = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
Format = table.Column<string>(type: "TEXT", nullable: false),
|
||||
Edition = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
VolumeNumber = table.Column<int>(type: "INTEGER", nullable: true),
|
||||
ASIN = table.Column<string>(type: "TEXT", maxLength: 10, nullable: true),
|
||||
GoodreadsId = table.Column<string>(type: "TEXT", nullable: true),
|
||||
LCCN = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OCLCNumber = table.Column<string>(type: "TEXT", nullable: true),
|
||||
OpenLibraryId = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
LibraryThingId = table.Column<string>(type: "TEXT", maxLength: 50, nullable: true),
|
||||
GoogleBooksId = table.Column<string>(type: "TEXT", maxLength: 12, nullable: true),
|
||||
BarnesAndNobleId = table.Column<string>(type: "TEXT", maxLength: 10, nullable: true),
|
||||
AppleBooksId = table.Column<string>(type: "TEXT", nullable: true),
|
||||
Created = table.Column<DateTime>(type: "TEXT", nullable: false),
|
||||
Updated = table.Column<DateTime>(type: "TEXT", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Books", x => x.Id);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Genres",
|
||||
columns: table => new
|
||||
{
|
||||
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Genres", x => x.Name);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "Tags",
|
||||
columns: table => new
|
||||
{
|
||||
Name = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_Tags", x => x.Name);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BookISBNs",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
ISBN = table.Column<string>(type: "TEXT", maxLength: 13, nullable: false),
|
||||
Format = table.Column<string>(type: "TEXT", maxLength: 6, nullable: false),
|
||||
BookId = table.Column<Guid>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BookISBNs", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_BookISBNs_Books_BookId",
|
||||
column: x => x.BookId,
|
||||
principalTable: "Books",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BookRatings",
|
||||
columns: table => new
|
||||
{
|
||||
Id = table.Column<int>(type: "INTEGER", nullable: false)
|
||||
.Annotation("Sqlite:Autoincrement", true),
|
||||
Source = table.Column<string>(type: "TEXT", maxLength: 50, nullable: false),
|
||||
BookId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
Value = table.Column<decimal>(type: "decimal(3,2)", nullable: false),
|
||||
MaxValue = table.Column<decimal>(type: "decimal(3,2)", nullable: false),
|
||||
VoteCount = table.Column<int>(type: "INTEGER", nullable: true)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BookRatings", x => x.Id);
|
||||
table.ForeignKey(
|
||||
name: "FK_BookRatings_Books_BookId",
|
||||
column: x => x.BookId,
|
||||
principalTable: "Books",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BookGenres",
|
||||
columns: table => new
|
||||
{
|
||||
BookId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
GenreId = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BookGenres", x => new { x.BookId, x.GenreId });
|
||||
table.ForeignKey(
|
||||
name: "FK_BookGenres_Books_BookId",
|
||||
column: x => x.BookId,
|
||||
principalTable: "Books",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_BookGenres_Genres_GenreId",
|
||||
column: x => x.GenreId,
|
||||
principalTable: "Genres",
|
||||
principalColumn: "Name",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateTable(
|
||||
name: "BookTags",
|
||||
columns: table => new
|
||||
{
|
||||
BookId = table.Column<Guid>(type: "TEXT", nullable: false),
|
||||
TagId = table.Column<string>(type: "TEXT", nullable: false)
|
||||
},
|
||||
constraints: table =>
|
||||
{
|
||||
table.PrimaryKey("PK_BookTags", x => new { x.BookId, x.TagId });
|
||||
table.ForeignKey(
|
||||
name: "FK_BookTags_Books_BookId",
|
||||
column: x => x.BookId,
|
||||
principalTable: "Books",
|
||||
principalColumn: "Id",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
table.ForeignKey(
|
||||
name: "FK_BookTags_Tags_TagId",
|
||||
column: x => x.TagId,
|
||||
principalTable: "Tags",
|
||||
principalColumn: "Name",
|
||||
onDelete: ReferentialAction.Cascade);
|
||||
});
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BookGenres_GenreId",
|
||||
table: "BookGenres",
|
||||
column: "GenreId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BookISBNs_BookId",
|
||||
table: "BookISBNs",
|
||||
column: "BookId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BookRatings_BookId",
|
||||
table: "BookRatings",
|
||||
column: "BookId");
|
||||
|
||||
migrationBuilder.CreateIndex(
|
||||
name: "IX_BookTags_TagId",
|
||||
table: "BookTags",
|
||||
column: "TagId");
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void Down(MigrationBuilder migrationBuilder)
|
||||
{
|
||||
migrationBuilder.DropTable(
|
||||
name: "BookGenres");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "BookISBNs");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "BookRatings");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "BookTags");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Genres");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Books");
|
||||
|
||||
migrationBuilder.DropTable(
|
||||
name: "Tags");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,321 @@
|
||||
// <auto-generated />
|
||||
using System;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||
|
||||
#nullable disable
|
||||
|
||||
namespace Lumina.DataAccess.Common.Migrations
|
||||
{
|
||||
[DbContext(typeof(LuminaDbContext))]
|
||||
partial class LuminaDbContextModelSnapshot : ModelSnapshot
|
||||
{
|
||||
protected override void BuildModel(ModelBuilder modelBuilder)
|
||||
{
|
||||
#pragma warning disable 612, 618
|
||||
modelBuilder.HasAnnotation("ProductVersion", "8.0.8");
|
||||
|
||||
modelBuilder.Entity("BookGenres", b =>
|
||||
{
|
||||
b.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("GenreId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("BookId", "GenreId");
|
||||
|
||||
b.HasIndex("GenreId");
|
||||
|
||||
b.ToTable("BookGenres", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookTags", b =>
|
||||
{
|
||||
b.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.Property<string>("TagId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("BookId", "TagId");
|
||||
|
||||
b.HasIndex("TagId");
|
||||
|
||||
b.ToTable("BookTags", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
|
||||
{
|
||||
b.Property<Guid>("Id")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(0);
|
||||
|
||||
b.Property<string>("ASIN")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(21);
|
||||
|
||||
b.Property<string>("AppleBooksId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(29);
|
||||
|
||||
b.Property<string>("BarnesAndNobleId")
|
||||
.HasMaxLength(10)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(28);
|
||||
|
||||
b.Property<DateTime>("Created")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(30);
|
||||
|
||||
b.Property<string>("Description")
|
||||
.HasMaxLength(2000)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(3);
|
||||
|
||||
b.Property<string>("Edition")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(19);
|
||||
|
||||
b.Property<string>("Format")
|
||||
.IsRequired()
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(18);
|
||||
|
||||
b.Property<string>("GoodreadsId")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(22);
|
||||
|
||||
b.Property<string>("GoogleBooksId")
|
||||
.HasMaxLength(12)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(27);
|
||||
|
||||
b.Property<string>("LCCN")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(23);
|
||||
|
||||
b.Property<string>("LanguageCode")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(10);
|
||||
|
||||
b.Property<string>("LanguageName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(11);
|
||||
|
||||
b.Property<string>("LanguageNativeName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(12);
|
||||
|
||||
b.Property<string>("LibraryThingId")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(26);
|
||||
|
||||
b.Property<string>("OCLCNumber")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(24);
|
||||
|
||||
b.Property<string>("OpenLibraryId")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(25);
|
||||
|
||||
b.Property<string>("OriginalLanguageCode")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(13);
|
||||
|
||||
b.Property<string>("OriginalLanguageName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(14);
|
||||
|
||||
b.Property<string>("OriginalLanguageNativeName")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(15);
|
||||
|
||||
b.Property<DateOnly?>("OriginalReleaseDate")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(4);
|
||||
|
||||
b.Property<int?>("OriginalReleaseYear")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(5);
|
||||
|
||||
b.Property<string>("OriginalTitle")
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(2);
|
||||
|
||||
b.Property<int?>("PageCount")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(17);
|
||||
|
||||
b.Property<string>("Publisher")
|
||||
.HasMaxLength(100)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(16);
|
||||
|
||||
b.Property<DateOnly?>("ReReleaseDate")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(6);
|
||||
|
||||
b.Property<int?>("ReReleaseYear")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(7);
|
||||
|
||||
b.Property<string>("ReleaseCountry")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(8);
|
||||
|
||||
b.Property<string>("ReleaseVersion")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(9);
|
||||
|
||||
b.Property<string>("Title")
|
||||
.IsRequired()
|
||||
.HasMaxLength(255)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(1);
|
||||
|
||||
b.Property<DateTime?>("Updated")
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnOrder(31);
|
||||
|
||||
b.Property<int?>("VolumeNumber")
|
||||
.HasColumnType("INTEGER")
|
||||
.HasColumnOrder(20);
|
||||
|
||||
b.HasKey("Id");
|
||||
|
||||
b.ToTable("Books", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.Models.Common.GenreDto", b =>
|
||||
{
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Name");
|
||||
|
||||
b.ToTable("Genres", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.Models.Common.TagDto", b =>
|
||||
{
|
||||
b.Property<string>("Name")
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b.HasKey("Name");
|
||||
|
||||
b.ToTable("Tags", (string)null);
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookGenres", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("BookId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.Models.Common.GenreDto", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("GenreId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("BookTags", b =>
|
||||
{
|
||||
b.HasOne("Lumina.Application.Common.Models.Books.BookDto", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("BookId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
|
||||
b.HasOne("Lumina.Application.Common.Models.Common.TagDto", null)
|
||||
.WithMany()
|
||||
.HasForeignKey("TagId")
|
||||
.OnDelete(DeleteBehavior.Cascade)
|
||||
.IsRequired();
|
||||
});
|
||||
|
||||
modelBuilder.Entity("Lumina.Application.Common.Models.Books.BookDto", b =>
|
||||
{
|
||||
b.OwnsMany("Lumina.Application.Common.Models.Books.BookRatingDto", "Ratings", b1 =>
|
||||
{
|
||||
b1.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b1.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<decimal>("MaxValue")
|
||||
.HasColumnType("decimal(3,2)");
|
||||
|
||||
b1.Property<string>("Source")
|
||||
.IsRequired()
|
||||
.HasMaxLength(50)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<decimal>("Value")
|
||||
.HasColumnType("decimal(3,2)");
|
||||
|
||||
b1.Property<int?>("VoteCount")
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b1.HasKey("Id");
|
||||
|
||||
b1.HasIndex("BookId");
|
||||
|
||||
b1.ToTable("BookRatings", (string)null);
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("BookId");
|
||||
});
|
||||
|
||||
b.OwnsMany("Lumina.Application.Common.Models.Books.IsbnDto", "ISBNs", b1 =>
|
||||
{
|
||||
b1.Property<int>("Id")
|
||||
.ValueGeneratedOnAdd()
|
||||
.HasColumnType("INTEGER");
|
||||
|
||||
b1.Property<Guid>("BookId")
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<string>("Format")
|
||||
.IsRequired()
|
||||
.HasMaxLength(6)
|
||||
.HasColumnType("TEXT");
|
||||
|
||||
b1.Property<string>("Value")
|
||||
.IsRequired()
|
||||
.HasMaxLength(13)
|
||||
.HasColumnType("TEXT")
|
||||
.HasColumnName("ISBN");
|
||||
|
||||
b1.HasKey("Id");
|
||||
|
||||
b1.HasIndex("BookId");
|
||||
|
||||
b1.ToTable("BookISBNs", (string)null);
|
||||
|
||||
b1.WithOwner()
|
||||
.HasForeignKey("BookId");
|
||||
});
|
||||
|
||||
b.Navigation("ISBNs");
|
||||
|
||||
b.Navigation("Ratings");
|
||||
});
|
||||
#pragma warning restore 612, 618
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using ErrorOr;
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Books;
|
||||
using Lumina.Application.Common.Models.Books;
|
||||
using Lumina.DataAccess.Core.UoW;
|
||||
using Lumina.Domain.Common.Errors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Core.Repositories.Books;
|
||||
|
||||
/// <summary>
|
||||
/// Repository for books.
|
||||
/// </summary>
|
||||
internal sealed class BookRepository : IBookRepository
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly LuminaDbContext _luminaDbContext;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="BookRepository"/> class.
|
||||
/// </summary>
|
||||
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
|
||||
public BookRepository(LuminaDbContext luminaDbContext)
|
||||
{
|
||||
_luminaDbContext = luminaDbContext;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Adds a new book.
|
||||
/// </summary>
|
||||
/// <param name="book">The book to add.</param>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> representing either a successfull operation, or an error.</returns>
|
||||
public async Task<ErrorOr<Created>> InsertAsync(BookDto book, CancellationToken cancellationToken)
|
||||
{
|
||||
var jobExists = await _luminaDbContext.Books.AnyAsync(_book => _book.Id == book.Id, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||
if (jobExists)
|
||||
return Errors.WrittenContent.BookAlreadyExists;
|
||||
_luminaDbContext.Books.Add(book);
|
||||
return Result.Created;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets all books.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
/// <returns>An <see cref="ErrorOr{T}"/> containing either a collection of <see cref="BookDto"/>, or an error.</returns>
|
||||
public async Task<ErrorOr<IEnumerable<BookDto>>> GetAllAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
return await _luminaDbContext.Books.ToListAsync(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
|
||||
|
||||
/// <summary>
|
||||
/// Repositories abstract factory.
|
||||
/// </summary>
|
||||
public interface IRepositoryFactory
|
||||
{
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new repository of type <typeparamref name="TResult"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">The type of repository to create.</typeparam>
|
||||
/// <returns>A repository of type <typeparamref name="TResult"/>.</returns>
|
||||
TResult CreateRepository<TResult>() where TResult : notnull;
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
|
||||
|
||||
/// <summary>
|
||||
/// Custom collection for storing repositories.
|
||||
/// </summary>
|
||||
public class RepositoryDictionary
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly List<KeyValuePair<Type, object>> _container = [];
|
||||
#endregion
|
||||
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public int Count { get { return _container.Count; } }
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Resets the collection of repositories.
|
||||
/// </summary>
|
||||
public void Clear()
|
||||
{
|
||||
_container.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a repository of type <typeparamref name="TParam"/> to the collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="TParam">The type of the repository to add to the collection.</typeparam>
|
||||
/// <param name="value">The repository to add.</param>
|
||||
public void Add<TParam>(TParam value) where TParam : notnull
|
||||
{
|
||||
// enforce adding rules
|
||||
if (value == null)
|
||||
throw new ArgumentException("Value cannot be null!");
|
||||
if (_container.Any(e => e.Key == value.GetType()))
|
||||
throw new ArgumentException("Duplicate values are not allowed!");
|
||||
// check if the value implements an interface that implements IRepository
|
||||
bool implementsRepository = value.GetType()
|
||||
.GetInterfaces()
|
||||
.Any(e => e.GetInterfaces()
|
||||
.Any(i => i.IsGenericType &&
|
||||
i.GetGenericTypeDefinition() == typeof(IRepository<>)));
|
||||
if (implementsRepository)
|
||||
_container.Add(new KeyValuePair<Type, object>(value.GetType(), value));
|
||||
else
|
||||
throw new ArgumentException("Value must implement IRepository interface!");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets a repository of type <typeparamref name="TResult"/> from the collection.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">The type of the repository interface to get from the collection.</typeparam>
|
||||
/// <param name="key">The concrete type of the repository interface to get.</param>
|
||||
/// <returns>A repository implementing <typeparamref name="TResult"/>.</returns>
|
||||
public TResult Get<TResult>(Type key)
|
||||
{
|
||||
return (TResult)_container.FirstOrDefault(e => e.Key == key).Value;
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Core.Repositories.Common.Factory;
|
||||
|
||||
/// <summary>
|
||||
/// Concrete implementation for the repositories abstract factory.
|
||||
/// </summary>
|
||||
public class RepositoryFactory : IRepositoryFactory
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly IServiceProvider _serviceProvider;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="serviceProvider">The service provider.</param>
|
||||
public RepositoryFactory(IServiceProvider serviceProvider)
|
||||
{
|
||||
_serviceProvider = serviceProvider;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Creates a new repository of type <typeparamref name="TResult"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="TResult">The type of repository to create.</typeparam>
|
||||
/// <returns>A repository of type <typeparamref name="TResult"/>.</returns>
|
||||
/// <exception cref="ArgumentException">Thrown when the type of the requested repository has not been registered.</exception>
|
||||
public TResult CreateRepository<TResult>() where TResult : notnull
|
||||
{
|
||||
return _serviceProvider.GetRequiredService<TResult>() ?? throw new ArgumentException();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.Models.Books;
|
||||
using Lumina.Application.Common.Models.Common;
|
||||
using Lumina.Domain.Common.Events;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Core.UoW;
|
||||
|
||||
/// <summary>
|
||||
/// DbContext for the Lumina application.
|
||||
/// </summary>
|
||||
/// <remarks>To add a new migration: add-migration InitialMigration -p Lumina.DataAccess -s Lumina.Presentation.Api -o Common\Migrations</remarks>
|
||||
/// <remarks>To update the database: update-database -p Lumina.DataAccess -s Lumina.Presentation.Api</remarks>
|
||||
public class LuminaDbContext : DbContext
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public DbSet<BookDto> Books { get; set; } = null!;
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="options">The options for configuring the database context.</param>
|
||||
public LuminaDbContext(DbContextOptions<LuminaDbContext> options) : base(options)
|
||||
{
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Configures the entity mappings for the database context.
|
||||
/// </summary>
|
||||
/// <param name="modelBuilder">The model builder used to configure the entity mappings.</param>
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
// find all the entity configurations in the assembly and apply them
|
||||
modelBuilder
|
||||
.Ignore<List<IDomainEvent>>()
|
||||
.ApplyConfigurationsFromAssembly(typeof(LuminaDbContext).Assembly);
|
||||
|
||||
base.OnModelCreating(modelBuilder);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Overrides the SaveChanges method of the DbContext class to automatically set the Created and Updated properties of entities that implement the <see cref="IStorageEntity"/>.
|
||||
/// </summary>
|
||||
/// <returns>The number of objects written to the underlying database.</returns>
|
||||
public override int SaveChanges()
|
||||
{
|
||||
// get all the entity entries that are either added or modified
|
||||
var entries = ChangeTracker.Entries()
|
||||
.Where(e => e.Entity is IStorageEntity &&
|
||||
(e.State is EntityState.Added or EntityState.Modified));
|
||||
foreach (var entityEntry in entries)
|
||||
{
|
||||
// if the entity is in Added state, set the Created property to the current date and time
|
||||
if (entityEntry.State == EntityState.Added)
|
||||
((IStorageEntity)entityEntry.Entity).Created = DateTime.UtcNow;
|
||||
// otherwise, if the entity is in Modified state, set the Updated property to the current date and time
|
||||
else if (entityEntry.State == EntityState.Modified)
|
||||
((IStorageEntity)entityEntry.Entity).Updated = DateTime.UtcNow;
|
||||
}
|
||||
return base.SaveChanges();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
#region ========================================================================= USING =====================================================================================
|
||||
using Lumina.Application.Common.DataAccess.Repositories.Common.Base;
|
||||
using Lumina.Application.Common.DataAccess.UoW;
|
||||
using Lumina.DataAccess.Core.Repositories.Common.Factory;
|
||||
using System.Reflection;
|
||||
#endregion
|
||||
|
||||
namespace Lumina.DataAccess.Core.UoW;
|
||||
|
||||
/// <summary>
|
||||
/// Interaction boundary with the Data Access Layer.
|
||||
/// </summary>
|
||||
public class UnitOfWork : IUnitOfWork
|
||||
{
|
||||
#region ================================================================== FIELD MEMBERS ================================================================================
|
||||
private readonly LuminaDbContext _luminaDbContext;
|
||||
private readonly IRepositoryFactory _repositoryFactory;
|
||||
#endregion
|
||||
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
internal RepositoryDictionary Repositories { get; private set; } = new RepositoryDictionary();
|
||||
#endregion
|
||||
|
||||
#region ====================================================================== CTOR =====================================================================================
|
||||
/// <summary>
|
||||
/// Overload C-tor.
|
||||
/// </summary>
|
||||
/// <param name="repositoryFactory">The abstract factory used to generate repositories.</param>
|
||||
/// <param name="luminaDbContext">Injected Entity Framework DbContext.</param>
|
||||
public UnitOfWork(IRepositoryFactory repositoryFactory, LuminaDbContext luminaDbContext)
|
||||
{
|
||||
_repositoryFactory = repositoryFactory;
|
||||
_luminaDbContext = luminaDbContext;
|
||||
AddRepositories();
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region ===================================================================== METHODS ===================================================================================
|
||||
/// <summary>
|
||||
/// Adds all the repositories from the Data Access Layer so that they can be exposed to the Business Layer.
|
||||
/// </summary>
|
||||
internal void AddRepositories()
|
||||
{
|
||||
// get all the concrete implementations of IRepository<>
|
||||
IEnumerable<Type> repositoryClassTypes =
|
||||
Assembly.GetExecutingAssembly()
|
||||
.GetTypes()
|
||||
.Where(t => !t.IsInterface && !t.IsAbstract && t.GetInterfaces()
|
||||
.Any(i => i.IsGenericType &&
|
||||
i.GetGenericTypeDefinition() == typeof(IRepository<>)));
|
||||
// store all repositories
|
||||
foreach (Type repositoryClassType in repositoryClassTypes)
|
||||
{
|
||||
// get the interface that implements IRepository<> of the currently iterated repository class
|
||||
Type repositoryInterfaceType = repositoryClassType.GetInterfaces()
|
||||
.Where(i => !i.IsGenericType &&
|
||||
i.GetInterfaces()
|
||||
.Any(a => a.GetGenericTypeDefinition() == typeof(IRepository<>)))
|
||||
.First();
|
||||
// ask the concrete type for the repository interface type from the repositories factory;
|
||||
// because the method for creating a repository is generic and we need to call it with a runtime type, reflection is the only option
|
||||
object repositoryClass = typeof(IRepositoryFactory).GetMethod("CreateRepository")!
|
||||
.MakeGenericMethod(repositoryInterfaceType)
|
||||
.Invoke(_repositoryFactory, null)!;
|
||||
Repositories.Add(repositoryClass);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Exposes a repository of type <typeparamref name="TRepository"/> to the Business Logic Layer.
|
||||
/// </summary>
|
||||
/// <typeparam name="TRepository">The type of the exposed repository.</typeparam>
|
||||
/// <returns>A repository of type <typeparamref name="TRepository"/>.</returns>
|
||||
public TRepository GetRepository<TRepository>()
|
||||
{
|
||||
// get the repository type based on the type of the provided repository interface
|
||||
Type repositoryType = Assembly.GetExecutingAssembly()
|
||||
.GetTypes()
|
||||
.Where(type => !type.IsInterface && !type.IsAbstract && typeof(TRepository).IsAssignableFrom(type))
|
||||
.First();
|
||||
return Repositories.Get<TRepository>(repositoryType);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Resets the list of repositories.
|
||||
/// </summary>
|
||||
internal void ResetRepositories()
|
||||
{
|
||||
Repositories.Clear();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Saves the changes made to the database.
|
||||
/// </summary>
|
||||
/// <param name="cancellationToken">Cancellation token that can be used to stop the execution.</param>
|
||||
public async Task SaveChangesAsync(CancellationToken cancellationToken)
|
||||
{
|
||||
await _luminaDbContext.SaveChangesAsync(cancellationToken);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Opens a transaction.
|
||||
/// </summary>
|
||||
public void OpenTransaction()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Commits a transaction.
|
||||
/// </summary>
|
||||
public void CommitTransaction()
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
@@ -1,14 +1,32 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>..\..\bin\</BaseOutputPath>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net8.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
<BaseOutputPath>..\..\bin\</BaseOutputPath>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Lumina.Application\Lumina.Application.csproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Lumina.Application\Lumina.Application.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.8">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
|
||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.8">
|
||||
<PrivateAssets>all</PrivateAssets>
|
||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||
</PackageReference>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Common\Converters\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -12,6 +12,7 @@ public static partial class Errors
|
||||
public static class WrittenContent
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
public static Error BookAlreadyExists => Error.Conflict(nameof(BookAlreadyExists));
|
||||
public static Error IsbnValueCannotBeEmpty => Error.Validation(nameof(IsbnValueCannotBeEmpty));
|
||||
public static Error IsbnListCannotBeNull => Error.Validation(nameof(IsbnListCannotBeNull));
|
||||
public static Error InvalidIsbn10Format => Error.Validation(nameof(InvalidIsbn10Format));
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Lumina.Domain.Common.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Interface defining a domain event.
|
||||
/// </summary>
|
||||
public interface IDomainEvent
|
||||
{
|
||||
#region ==================================================================== PROPERTIES =================================================================================
|
||||
Guid Id { get; }
|
||||
DateTime OccurredOn { get; }
|
||||
#endregion
|
||||
}
|
||||
Reference in new issue
Block a user