From 655fa9529b9d0312c02f984fa9a1131e9fc6a798 Mon Sep 17 00:00:00 2001 From: Nikoo Asadnejad Date: Fri, 3 May 2024 11:45:56 +0330 Subject: [PATCH] feat: add entity configurations --- .../Shared/User/AggregateRoot/UserModel.cs | 2 +- .../Category/CategoryConfiguration.cs | 25 ++++++++++++++ .../ChangeHistoryConfiguration.cs | 15 +++++++++ .../OutBoxMessageConfiguration.cs | 20 +++++++++++ .../Product/ProductConfiguration.cs | 33 +++++++++++++++++++ 5 files changed, 94 insertions(+), 1 deletion(-) create mode 100644 Src/Product.Infrastructure/Data/EntitytypeConfigurations/Category/CategoryConfiguration.cs create mode 100644 Src/Product.Infrastructure/Data/EntitytypeConfigurations/ChangeHistory/ChangeHistoryConfiguration.cs create mode 100644 Src/Product.Infrastructure/Data/EntitytypeConfigurations/OutboxMessage/OutBoxMessageConfiguration.cs create mode 100644 Src/Product.Infrastructure/Data/EntitytypeConfigurations/Product/ProductConfiguration.cs diff --git a/Src/Product.Domain/Aggregates/Shared/User/AggregateRoot/UserModel.cs b/Src/Product.Domain/Aggregates/Shared/User/AggregateRoot/UserModel.cs index 96795c0..eb585fe 100644 --- a/Src/Product.Domain/Aggregates/Shared/User/AggregateRoot/UserModel.cs +++ b/Src/Product.Domain/Aggregates/Shared/User/AggregateRoot/UserModel.cs @@ -1,6 +1,6 @@ using Product.Domain.Shared.Base; -namespace Product.Domain.Shared.Entity; +namespace Product.Domain.Aggregates.Shared.User.AggregateRoot; public class UserModel : BaseEntity { diff --git a/Src/Product.Infrastructure/Data/EntitytypeConfigurations/Category/CategoryConfiguration.cs b/Src/Product.Infrastructure/Data/EntitytypeConfigurations/Category/CategoryConfiguration.cs new file mode 100644 index 0000000..7365e72 --- /dev/null +++ b/Src/Product.Infrastructure/Data/EntitytypeConfigurations/Category/CategoryConfiguration.cs @@ -0,0 +1,25 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Product.Domain.Aggregates.Category.AggregateRoot; + +namespace Product.Infrastructure.Data.EntitytypeConfigurations.Category; + +public class CategoryConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(c => c.Id); + + builder.Property(c => c.Id) + .IsRequired() + .ValueGeneratedOnAdd(); + + builder.Property(c => c.Title) + .IsRequired() + .HasMaxLength(250); + + builder.HasOne(c => c.SubCategory) + .WithMany() + .HasForeignKey(c => c.SubCategoryId); + } +} \ No newline at end of file diff --git a/Src/Product.Infrastructure/Data/EntitytypeConfigurations/ChangeHistory/ChangeHistoryConfiguration.cs b/Src/Product.Infrastructure/Data/EntitytypeConfigurations/ChangeHistory/ChangeHistoryConfiguration.cs new file mode 100644 index 0000000..89a9dd8 --- /dev/null +++ b/Src/Product.Infrastructure/Data/EntitytypeConfigurations/ChangeHistory/ChangeHistoryConfiguration.cs @@ -0,0 +1,15 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; + +namespace Product.Infrastructure.Data.EntitytypeConfigurations.ChangeHistory; + +public class ChangeLogConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(b => b.Id); + builder.Property(b => b.RelatedEntityType) + .HasMaxLength(150); + } +} + diff --git a/Src/Product.Infrastructure/Data/EntitytypeConfigurations/OutboxMessage/OutBoxMessageConfiguration.cs b/Src/Product.Infrastructure/Data/EntitytypeConfigurations/OutboxMessage/OutBoxMessageConfiguration.cs new file mode 100644 index 0000000..6fb170a --- /dev/null +++ b/Src/Product.Infrastructure/Data/EntitytypeConfigurations/OutboxMessage/OutBoxMessageConfiguration.cs @@ -0,0 +1,20 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Product.Domain.Aggregates.Shared.OutboxMessage.AggregateRoot; + +namespace Product.Infrastructure.Data.EntitytypeConfigurations.OutboxMessage; + +public class OutBoxMessageConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(b => b.Id); + + builder.Property(b => b.Type) + .IsRequired() + .HasMaxLength(150); + + builder.Property(b => b.Content) + .IsRequired(); + } +} \ No newline at end of file diff --git a/Src/Product.Infrastructure/Data/EntitytypeConfigurations/Product/ProductConfiguration.cs b/Src/Product.Infrastructure/Data/EntitytypeConfigurations/Product/ProductConfiguration.cs new file mode 100644 index 0000000..6d7bc81 --- /dev/null +++ b/Src/Product.Infrastructure/Data/EntitytypeConfigurations/Product/ProductConfiguration.cs @@ -0,0 +1,33 @@ +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata.Builders; +using Product.Domain.Aggregates.Category.AggregateRoot; +using Product.Domain.Aggregates.Product.AggregateRoot; + +namespace Product.Infrastructure.Data.EntitytypeConfigurations.Product; + +public class ProductConfiguration : IEntityTypeConfiguration +{ + public void Configure(EntityTypeBuilder builder) + { + builder.HasKey(p => p.Id); + + builder.Property(p => p.Id) + .IsRequired() + .ValueGeneratedOnAdd(); + + builder.Property(p => p.Title) + .IsRequired() + .HasMaxLength(250); + + builder.Property(p => p.SubTitle) + .HasMaxLength(500); + + builder.OwnsOne(p => p.Price); + + builder.HasOne(typeof(CategoryModel)) + .WithMany(); + + builder.HasMany(p => p.ProductComments) + .WithOne(); + } +} \ No newline at end of file