From 0c54b19085041f93ecf77a0d879a9693776c5aaa Mon Sep 17 00:00:00 2001 From: Ahmet Date: Tue, 22 Dec 2020 14:59:53 +0300 Subject: [PATCH] refactor content entity and added content renderer --- .../Volo/CmsKit/Contents/IContentRenderer.cs | 14 ----------- .../Contents/IContentRendererProvider.cs | 15 ------------ .../Volo/CmsKit/Contents/PlainTextRenderer.cs | 19 --------------- .../Contents/IContentRenderer.cs | 9 +++++++ .../Contents/PlainTextContentRenderer.cs | 13 ++++++++++ .../Volo/CmsKit/Contents/ContentConsts.cs | 15 ++++++++++++ .../Volo/CmsKit/Contents/IContent.cs | 7 ------ .../Volo/CmsKit/Contents/IEntityContent.cs | 8 ------- .../Volo/CmsKit/Contents/Content.cs | 24 +++++++++++++------ .../CmsKit/Contents/IContentRepository.cs | 10 ++++++++ .../Contents/EfCoreContentRepository.cs | 14 +++++++++++ .../Contents/MongoContentRepository.cs | 14 +++++++++++ 12 files changed, 92 insertions(+), 70 deletions(-) delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentRenderer.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentRendererProvider.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/PlainTextRenderer.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/IContentRenderer.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/PlainTextContentRenderer.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/ContentConsts.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/IContent.cs delete mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/IEntityContent.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs create mode 100644 modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentRenderer.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentRenderer.cs deleted file mode 100644 index 79efa468d7..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentRenderer.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Volo.CmsKit.Domain.Shared.Volo.CmsKit.Contents; - -namespace Volo.CmsKit.Common.Application.Contracts.Volo.CmsKit.Contents -{ - public interface IContentRenderer - { - Task RenderAsync(string content); - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentRendererProvider.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentRendererProvider.cs deleted file mode 100644 index 5a1f2077e7..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentRendererProvider.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Volo.CmsKit.Domain.Shared.Volo.CmsKit.Contents; - -namespace Volo.CmsKit.Common.Application.Contracts.Volo.CmsKit.Contents -{ - public interface IContentRendererProvider - { - Task GetContentRendererAsync(IEntityContent content); - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/PlainTextRenderer.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/PlainTextRenderer.cs deleted file mode 100644 index 4745954037..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/PlainTextRenderer.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Volo.Abp.DependencyInjection; -using Volo.CmsKit.Common.Application.Contracts.Volo.CmsKit.Contents; -using Volo.CmsKit.Domain.Shared.Volo.CmsKit.Contents; - -namespace Volo.CmsKit.Common.Application.Volo.CmsKit.Contents -{ - public class PlainTextRenderer : IContentRenderer, ITransientDependency - { - public Task RenderAsync(IContent content) - { - return Task.FromResult(content?.Value); - } - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/IContentRenderer.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/IContentRenderer.cs new file mode 100644 index 0000000000..af600d0382 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/IContentRenderer.cs @@ -0,0 +1,9 @@ +using System.Threading.Tasks; + +namespace Volo.CmsKit.Web.Contents +{ + public interface IContentRenderer + { + Task RenderAsync(string value); + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/PlainTextContentRenderer.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/PlainTextContentRenderer.cs new file mode 100644 index 0000000000..3f839947e3 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Contents/PlainTextContentRenderer.cs @@ -0,0 +1,13 @@ +using System.Threading.Tasks; +using Volo.Abp.DependencyInjection; + +namespace Volo.CmsKit.Web.Contents +{ + public class PlainTextContentRenderer : IContentRenderer, ITransientDependency + { + public Task RenderAsync(string value) + { + return Task.FromResult(value); + } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/ContentConsts.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/ContentConsts.cs new file mode 100644 index 0000000000..758a29e81f --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/ContentConsts.cs @@ -0,0 +1,15 @@ +using System; +using Volo.CmsKit.Entities; + +namespace Volo.CmsKit.Contents +{ + public static class ContentConsts + { + public static int MaxEntityTypeLength { get; set; } = CmsEntityConsts.MaxEntityTypeLength; + + public static int MaxEntityIdLength { get; set; } = CmsEntityConsts.MaxEntityIdLength; + + // TODO: consider + public static int MaxValueLength = int.MaxValue; + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/IContent.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/IContent.cs deleted file mode 100644 index e3fce8c01f..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/IContent.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Volo.CmsKit.Domain.Shared.Volo.CmsKit.Contents -{ - public interface IContent - { - string Value { get; set; } - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/IEntityContent.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/IEntityContent.cs deleted file mode 100644 index 31f5a3299b..0000000000 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Contents/IEntityContent.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Volo.CmsKit.Domain.Shared.Volo.CmsKit.Contents -{ - public interface IEntityContent : IContent - { - string EntityType { get; set; } - string EntityId { get; set; } - } -} diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs index 48ed1bfc34..34546f6111 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs @@ -1,17 +1,27 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp; using Volo.Abp.Domain.Entities.Auditing; -using Volo.CmsKit.Domain.Shared.Volo.CmsKit.Contents; -namespace Volo.CmsKit.Domain.Volo.CmsKit.Contents +namespace Volo.CmsKit.Contents { public class Content : FullAuditedAggregateRoot { - public string Value { get; set; } public string EntityType { get; set; } + public string EntityId { get; set; } + + public string Value { get; set; } + + protected Content() + { + + } + public Content(Guid id, [NotNull] string entityType, [NotNull] string entityId, [NotNull] string value) : base(id) + { + EntityType = Check.NotNullOrWhiteSpace(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength); + EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId), ContentConsts.MaxEntityIdLength); + Value = Check.NotNullOrWhiteSpace(value, nameof(value), ContentConsts.MaxValueLength); + } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs new file mode 100644 index 0000000000..994d2bd4ab --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/IContentRepository.cs @@ -0,0 +1,10 @@ +using System; +using Volo.Abp.Domain.Repositories; + +namespace Volo.CmsKit.Contents +{ + public interface IContentRepository : IBasicRepository + { + + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs new file mode 100644 index 0000000000..592fccb883 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs @@ -0,0 +1,14 @@ +using System; +using Volo.Abp.Domain.Repositories.EntityFrameworkCore; +using Volo.Abp.EntityFrameworkCore; +using Volo.CmsKit.EntityFrameworkCore; + +namespace Volo.CmsKit.Contents +{ + public class EfCoreContentRepository : EfCoreRepository, IContentRepository + { + public EfCoreContentRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) + { + } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs new file mode 100644 index 0000000000..e29b53d417 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs @@ -0,0 +1,14 @@ +using System; +using Volo.Abp.Domain.Repositories.MongoDB; +using Volo.Abp.MongoDB; +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.MongoDB.Contents +{ + public class MongoContentRepository : MongoDbRepository, IContentRepository + { + public MongoContentRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) + { + } + } +} \ No newline at end of file