From afc63a69d5b04ac6963566d76311e8706244ebc5 Mon Sep 17 00:00:00 2001 From: Nikoo Asadnejad Date: Fri, 3 May 2024 11:28:19 +0330 Subject: [PATCH] feat(domain): add changeHistory and outboxMessage --- .../AggregateRoot/ChangeHistory.cs | 20 +++++++++++++++++ .../AggregateRoot/OutBoxMessage.cs | 22 +++++++++++++++++++ .../Shared/User/AggregateRoot}/UserModel.cs | 0 Src/Product.Domain/Product.Domain.csproj | 1 + .../Interfaces/Command/IRepository.Async.cs | 2 +- .../Interfaces/Command/IRepository.Sync.cs | 2 +- .../Interfaces/IUnitOfWork.cs | 2 +- .../Query/IQueryGenericRepository.Async.cs | 2 +- .../Query/IQueryGenericRepository.Sync.cs | 2 +- .../Command/Repository.Async.cs | 2 +- .../Query/CacheRepository.cs | 2 +- .../Query/QueryGenericRepository.Async.cs | 2 +- .../Query/QueryGenericRepository.Sync.cs | 2 +- .../Data/Repository/UnitOfWork/UnitOfWork.cs | 2 +- 14 files changed, 53 insertions(+), 10 deletions(-) create mode 100644 Src/Product.Domain/Aggregates/Shared/ChangeHistory/AggregateRoot/ChangeHistory.cs create mode 100644 Src/Product.Domain/Aggregates/Shared/OutboxMessage/AggregateRoot/OutBoxMessage.cs rename Src/Product.Domain/{Shared/Entity => Aggregates/Shared/User/AggregateRoot}/UserModel.cs (100%) diff --git a/Src/Product.Domain/Aggregates/Shared/ChangeHistory/AggregateRoot/ChangeHistory.cs b/Src/Product.Domain/Aggregates/Shared/ChangeHistory/AggregateRoot/ChangeHistory.cs new file mode 100644 index 0000000..efa56ba --- /dev/null +++ b/Src/Product.Domain/Aggregates/Shared/ChangeHistory/AggregateRoot/ChangeHistory.cs @@ -0,0 +1,20 @@ +using System.Text.Json; +using Product.Domain.Shared.Base; + +namespace Product.Domain.Aggregates.Shared.ChangeHistory.AggregateRoot; + +public class ChangeHistory : BaseEntity +{ + public string OldValue { get; private set; } + public string NewValue { get;private set; } + public string RelatedEntityId { get; private set; } + public string RelatedEntityType { get; private set; } + + public void LogHistory(BaseEntity oldEntity , BaseEntity newEntity) + { + OldValue = JsonSerializer.Serialize(oldEntity); + NewValue = JsonSerializer.Serialize(oldEntity); + RelatedEntityId = oldEntity.Id.ToString(); + RelatedEntityType = oldEntity.GetType().Name; + } +} \ No newline at end of file diff --git a/Src/Product.Domain/Aggregates/Shared/OutboxMessage/AggregateRoot/OutBoxMessage.cs b/Src/Product.Domain/Aggregates/Shared/OutboxMessage/AggregateRoot/OutBoxMessage.cs new file mode 100644 index 0000000..23b0372 --- /dev/null +++ b/Src/Product.Domain/Aggregates/Shared/OutboxMessage/AggregateRoot/OutBoxMessage.cs @@ -0,0 +1,22 @@ +using System.Text.Json; +using Product.Domain.Shared.Base; +using Product.Domain.Shared.Events; + +namespace Product.Domain.Aggregates.Shared.OutboxMessage.AggregateRoot; + +public class OutBoxMessage : BaseEntity +{ + public OutBoxMessage(string type , string content) + { + Type = type; + Content = content; + } + public OutBoxMessage(IDomainEvent domainEvent) + { + Type = domainEvent.GetType().Name; + Content = JsonSerializer.Serialize(domainEvent); + } + + public string Type { get; private set; } + public string Content { get; private set; } +} \ No newline at end of file diff --git a/Src/Product.Domain/Shared/Entity/UserModel.cs b/Src/Product.Domain/Aggregates/Shared/User/AggregateRoot/UserModel.cs similarity index 100% rename from Src/Product.Domain/Shared/Entity/UserModel.cs rename to Src/Product.Domain/Aggregates/Shared/User/AggregateRoot/UserModel.cs diff --git a/Src/Product.Domain/Product.Domain.csproj b/Src/Product.Domain/Product.Domain.csproj index 076e7bf..8daf9f8 100644 --- a/Src/Product.Domain/Product.Domain.csproj +++ b/Src/Product.Domain/Product.Domain.csproj @@ -9,6 +9,7 @@ + diff --git a/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Async.cs b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Async.cs index 2880080..54eaeb2 100644 --- a/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Async.cs +++ b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Async.cs @@ -1,7 +1,7 @@ using System.Linq.Expressions; using Product.Domain.Shared.Base; -namespace Product.Domain.Shared.GenericRepository.GenericRepository.Command; +namespace Product.Domain.Shared.GenericRepository.Interfaces.Command; public partial interface IRepository where T : IAggregateRoot { diff --git a/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Sync.cs b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Sync.cs index 178ed4f..ae053aa 100644 --- a/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Sync.cs +++ b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Command/IRepository.Sync.cs @@ -1,6 +1,6 @@ using Product.Domain.Shared.Base; -namespace Product.Domain.Shared.GenericRepository.GenericRepository.Command; +namespace Product.Domain.Shared.GenericRepository.Interfaces.Command; public partial interface IRepository where T : IAggregateRoot { diff --git a/Src/Product.Domain/Shared/GenericRepository/Interfaces/IUnitOfWork.cs b/Src/Product.Domain/Shared/GenericRepository/Interfaces/IUnitOfWork.cs index 2f25849..736bfd4 100644 --- a/Src/Product.Domain/Shared/GenericRepository/Interfaces/IUnitOfWork.cs +++ b/Src/Product.Domain/Shared/GenericRepository/Interfaces/IUnitOfWork.cs @@ -1,4 +1,4 @@ -namespace Product.Domain.Shared.GenericRepository.UnitOfWork; +namespace Product.Domain.Shared.GenericRepository.Interfaces; public interface IUnitOfWork { diff --git a/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Async.cs b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Async.cs index 0501875..7e3fdd6 100644 --- a/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Async.cs +++ b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Async.cs @@ -2,7 +2,7 @@ using Product.Domain.Shared.Base; using Product.Domain.Shared.GenericRepository.Enums; -namespace Product.Domain.Shared.GenericRepository.GenericRepository.Query; +namespace Product.Domain.Shared.GenericRepository.Interfaces.Query; public partial interface IQueryGenericRepository where T : BaseEntity { diff --git a/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Sync.cs b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Sync.cs index 04e1f63..fcb5263 100644 --- a/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Sync.cs +++ b/Src/Product.Domain/Shared/GenericRepository/Interfaces/Query/IQueryGenericRepository.Sync.cs @@ -2,7 +2,7 @@ using Product.Domain.Shared.Base; using Product.Domain.Shared.GenericRepository.Enums; -namespace Product.Domain.Shared.GenericRepository.GenericRepository.Query; +namespace Product.Domain.Shared.GenericRepository.Interfaces.Query; public partial interface IQueryGenericRepository where T : BaseEntity { diff --git a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Async.cs b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Async.cs index 1784744..67b5610 100644 --- a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Async.cs +++ b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Command/Repository.Async.cs @@ -1,7 +1,7 @@ using System.Linq.Expressions; using Microsoft.EntityFrameworkCore; using Product.Domain.Shared.Base; -using Product.Domain.Shared.GenericRepository.GenericRepository.Command; +using Product.Domain.Shared.GenericRepository.Interfaces.Command; using Product.Infrastructure.Data.Context; namespace Product.Infrastructure.Data.Repository.GenericRepository.Command; diff --git a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/CacheRepository.cs b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/CacheRepository.cs index 1487c05..81b1d68 100644 --- a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/CacheRepository.cs +++ b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/CacheRepository.cs @@ -2,7 +2,7 @@ using Microsoft.Extensions.Caching.Memory; using Product.Domain.Shared.Base; using Product.Domain.Shared.GenericRepository.Enums; -using Product.Domain.Shared.GenericRepository.GenericRepository.Query; +using Product.Domain.Shared.GenericRepository.Interfaces.Query; namespace Product.Infrastructure.Data.Repository.GenericRepository.Query; diff --git a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Async.cs b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Async.cs index 08aa513..7d4fcb4 100644 --- a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Async.cs +++ b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Async.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore; using Product.Domain.Shared.Base; using Product.Domain.Shared.GenericRepository.Enums; -using Product.Domain.Shared.GenericRepository.GenericRepository.Query; +using Product.Domain.Shared.GenericRepository.Interfaces.Query; using Product.Infrastructure.Data.Context; namespace Product.Infrastructure.Data.Repository.GenericRepository.Query; diff --git a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Sync.cs b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Sync.cs index 196a9d1..31ef595 100644 --- a/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Sync.cs +++ b/Src/Product.Infrastructure/Data/Repository/GenericRepository/Query/QueryGenericRepository.Sync.cs @@ -2,7 +2,7 @@ using Microsoft.EntityFrameworkCore; using Product.Domain.Shared.Base; using Product.Domain.Shared.GenericRepository.Enums; -using Product.Domain.Shared.GenericRepository.GenericRepository.Query; +using Product.Domain.Shared.GenericRepository.Interfaces.Query; namespace Product.Infrastructure.Data.Repository.GenericRepository.Query; diff --git a/Src/Product.Infrastructure/Data/Repository/UnitOfWork/UnitOfWork.cs b/Src/Product.Infrastructure/Data/Repository/UnitOfWork/UnitOfWork.cs index e0c945f..8edd870 100644 --- a/Src/Product.Infrastructure/Data/Repository/UnitOfWork/UnitOfWork.cs +++ b/Src/Product.Infrastructure/Data/Repository/UnitOfWork/UnitOfWork.cs @@ -1,6 +1,6 @@ using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; -using Product.Domain.Shared.GenericRepository.UnitOfWork; +using Product.Domain.Shared.GenericRepository.Interfaces; namespace Product.Infrastructure.Data.Repository.UnitOfWork;