Browse Source

Merge pull request #7755 from abpframework/content-refactoring

Content refactoring
pull/7781/head
Ahmet Çotur 5 years ago
committed by GitHub
parent
commit
841a76dbea
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs
  2. 18
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs
  3. 9
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs
  4. 8
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs
  5. 8
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs
  6. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/IPagePublicAppService.cs
  7. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Contents/ContentPublicAppService.cs
  8. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs
  9. 13
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Pages/PagesPublicController.cs
  10. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Controllers/PageController.cs
  11. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
  12. 4
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Pages/PagePublicAppService_Tests.cs

2
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs

@ -56,7 +56,7 @@ namespace Volo.CmsKit.Admin.Contents
return MapToGetOutputDto(entity);
}
public async Task<ContentDto> GetAsync(
public virtual async Task<ContentDto> GetAsync(
[NotNull] string entityType,
[NotNull] string entityId)
{

18
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs

@ -8,12 +8,16 @@ namespace Volo.CmsKit.Contents
{
public class Content : FullAuditedAggregateRoot<Guid>, IMultiTenant
{
[CanBeNull]
public virtual Guid? TenantId { get; protected set; }
[NotNull]
public virtual string EntityType { get; protected set; }
public virtual string EntityId { get; set; }
[NotNull]
public virtual string EntityId { get; protected set; }
[NotNull]
public virtual string Value { get; protected set; }
protected Content()
@ -23,16 +27,22 @@ namespace Volo.CmsKit.Contents
public Content(Guid id, [NotNull] string entityType, [NotNull] string entityId, [NotNull] string value, Guid? tenantId = null) : base(id)
{
EntityType = Check.NotNullOrWhiteSpace(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength);
EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId), ContentConsts.MaxEntityIdLength);
SetValue(value);
EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength);
Value = Check.NotNullOrEmpty(value, nameof(value), ContentConsts.MaxValueLength);
TenantId = tenantId;
}
public void SetValue([NotNull] string value)
{
Value = Check.NotNullOrWhiteSpace(value, nameof(value), ContentConsts.MaxValueLength);
Value = Check.NotNullOrEmpty(value, nameof(value), ContentConsts.MaxValueLength);
}
public void SetEntity([NotNull] string entityType, [NotNull] string entityId)
{
EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength);
EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId), ContentConsts.MaxEntityIdLength);
}
}
}

9
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentManager.cs

@ -18,14 +18,15 @@ namespace Volo.CmsKit.Contents
ContentRepository = contentRepository;
}
public async Task<Content> InsertAsync(Content content, CancellationToken cancellationToken = default)
public virtual async Task<Content> InsertAsync(Content content, CancellationToken cancellationToken = default)
{
if (await ContentRepository.ExistsAsync(content.EntityType, content.EntityId, content.TenantId, cancellationToken))
if (await ContentRepository.ExistsAsync(content.EntityType, content.EntityId, content.TenantId,
cancellationToken))
{
throw new ContentAlreadyExistException(content.EntityType, content.EntityId);
}
return await ContentRepository.InsertAsync(content);
return await ContentRepository.InsertAsync(content, cancellationToken: cancellationToken);
}
}
}
}

8
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs

@ -15,7 +15,7 @@ namespace Volo.CmsKit.Contents
{
}
public Task<Content> GetAsync(
public virtual Task<Content> GetAsync(
string entityType,
string entityId,
Guid? tenantId = null,
@ -29,7 +29,7 @@ namespace Volo.CmsKit.Contents
);
}
public Task<Content> FindAsync(
public virtual Task<Content> FindAsync(
string entityType,
string entityId,
Guid? tenantId = null,
@ -43,7 +43,7 @@ namespace Volo.CmsKit.Contents
);
}
public Task DeleteAsync(
public virtual Task DeleteAsync(
string entityType,
string entityId,
Guid? tenantId = null,
@ -56,7 +56,7 @@ namespace Volo.CmsKit.Contents
cancellationToken: GetCancellationToken(cancellationToken));
}
public async Task<bool> ExistsAsync(
public virtual async Task<bool> ExistsAsync(
[NotNull] string entityType,
[NotNull] string entityId,
Guid? tenantId = null,

8
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs

@ -15,7 +15,7 @@ namespace Volo.CmsKit.MongoDB.Contents
{
}
public Task<Content> GetAsync(
public virtual Task<Content> GetAsync(
string entityType,
string entityId,
Guid? tenantId = null,
@ -29,7 +29,7 @@ namespace Volo.CmsKit.MongoDB.Contents
);
}
public Task<Content> FindAsync(
public virtual Task<Content> FindAsync(
string entityType,
string entityId,
Guid? tenantId = null,
@ -43,7 +43,7 @@ namespace Volo.CmsKit.MongoDB.Contents
);
}
public Task DeleteAsync(string entityType, string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default)
public virtual Task DeleteAsync(string entityType, string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default)
{
return DeleteAsync(x =>
x.EntityType == entityType &&
@ -52,7 +52,7 @@ namespace Volo.CmsKit.MongoDB.Contents
cancellationToken: GetCancellationToken(cancellationToken));
}
public async Task<bool> ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default)
public virtual async Task<bool> ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default)
{
return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x =>
x.EntityType == entityType &&

2
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/IPageAppService.cs → modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/IPagePublicAppService.cs

@ -3,7 +3,7 @@ using JetBrains.Annotations;
namespace Volo.CmsKit.Public.Pages
{
public interface IPageAppService
public interface IPagePublicAppService
{
Task<PageDto> FindByUrlAsync([NotNull] string url);
}

6
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Contents/ContentAppService.cs → modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Contents/ContentPublicAppService.cs

@ -3,11 +3,11 @@ using Volo.CmsKit.Contents;
namespace Volo.CmsKit.Public.Contents
{
public class ContentAppService : CmsKitAppServiceBase, IContentAppService
public class ContentPublicAppService : CmsKitAppServiceBase, IContentAppService
{
protected readonly IContentRepository ContentRepository;
protected IContentRepository ContentRepository { get; }
public ContentAppService(IContentRepository contentRepository)
public ContentPublicAppService(IContentRepository contentRepository)
{
ContentRepository = contentRepository;
}

4
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PageAppService.cs → modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs

@ -3,11 +3,11 @@ using Volo.CmsKit.Pages;
namespace Volo.CmsKit.Public.Pages
{
public class PageAppService : CmsKitPublicAppServiceBase, IPageAppService
public class PagePublicAppService : CmsKitPublicAppServiceBase, IPagePublicAppService
{
protected readonly IPageRepository PageRepository;
public PageAppService(IPageRepository pageRepository)
public PagePublicAppService(IPageRepository pageRepository)
{
PageRepository = pageRepository;
}

13
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Pages/PagesPublicController.cs

@ -1,24 +1,27 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.GlobalFeatures;
namespace Volo.CmsKit.Public.Pages
{
[RequiresGlobalFeature(typeof(PagesFeature))]
[RemoteService(Name = CmsKitPublicRemoteServiceConsts.RemoteServiceName)]
[Area("cms-kit")]
[Route("api/cms-kit-public/comments")]
public class PagesPublicController : IPageAppService
[Route("api/cms-kit-public/pages")]
public class PagesPublicController : IPagePublicAppService
{
protected readonly IPageAppService PageAppService;
protected IPagePublicAppService PageAppService { get; }
public PagesPublicController(IPageAppService pageAppService)
public PagesPublicController(IPagePublicAppService pageAppService)
{
PageAppService = pageAppService;
}
[HttpGet]
[Route("url/{url}")]
public Task<PageDto> FindByUrlAsync(string url)
public virtual Task<PageDto> FindByUrlAsync(string url)
{
return PageAppService.FindByUrlAsync(url);
}

4
modules/cms-kit/src/Volo.CmsKit.Public.Web/Controllers/PageController.cs

@ -14,9 +14,9 @@ namespace Volo.CmsKit.Public.Web.Controllers
[RequiresGlobalFeature(typeof(PagesFeature))]
public class PageController : CmsKitPublicControllerBase
{
protected IPageAppService PageAppService { get; }
protected IPagePublicAppService PageAppService { get; }
public PageController(IPageAppService pageAppService)
public PageController(IPagePublicAppService pageAppService)
{
PageAppService = pageAppService;
}

4
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs

@ -9,9 +9,9 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
[ViewComponent(Name = "CmsDefaultPage")]
public class DefaultPageViewComponent : AbpViewComponent
{
protected readonly IPageAppService PageAppService;
protected readonly IPagePublicAppService PageAppService;
public DefaultPageViewComponent(IPageAppService pageAppService)
public DefaultPageViewComponent(IPagePublicAppService pageAppService)
{
PageAppService = pageAppService;
}

4
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Pages/PagePublicAppService_Tests.cs

@ -9,12 +9,12 @@ namespace Volo.CmsKit.Pages
public class PagePublicAppService_Tests : CmsKitApplicationTestBase
{
private readonly CmsKitTestData _data;
private readonly IPageAppService _pageAppService;
private readonly IPagePublicAppService _pageAppService;
public PagePublicAppService_Tests()
{
_data = GetRequiredService<CmsKitTestData>();
_pageAppService = GetRequiredService<IPageAppService>();
_pageAppService = GetRequiredService<IPagePublicAppService>();
}
[Fact]

Loading…
Cancel
Save