diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/GetContentInput.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/GetContentInput.cs index 8efddd1e35..ab3bafc51f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/GetContentInput.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/GetContentInput.cs @@ -1,4 +1,4 @@ -namespace Volo.CmsKit.Common.Application.Contracts.Volo.CmsKit.Contents +namespace Volo.CmsKit.Contents { public class GetContentInput { diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentAppService.cs index 714fb6e4fb..fae0bd5271 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Contents/IContentAppService.cs @@ -1,5 +1,4 @@ using System.Threading.Tasks; -using Volo.CmsKit.Common.Application.Contracts.Volo.CmsKit.Contents; namespace Volo.CmsKit.Contents { diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/CheckUrlInputDto.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/CheckUrlInputDto.cs new file mode 100644 index 0000000000..6047526e03 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/CheckUrlInputDto.cs @@ -0,0 +1,12 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; + +namespace Volo.CmsKit.Pages +{ + public class CheckUrlInputDto + { + [Required] + [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxUrlLength))] + public string Url { get; set; } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/CreatePageInputDto.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/CreatePageInputDto.cs new file mode 100644 index 0000000000..7f5ce67260 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/CreatePageInputDto.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; + +namespace Volo.CmsKit.Pages +{ + public class CreatePageInputDto + { + [Required] + [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxTitleLength))] + public string Title { get; set; } + + [Required] + [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxUrlLength))] + public string Url { get; set; } + + [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))] + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/CreatePageWithContentInputDto.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/CreatePageWithContentInputDto.cs new file mode 100644 index 0000000000..ddbf7ce373 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/CreatePageWithContentInputDto.cs @@ -0,0 +1,24 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.Pages +{ + public class CreatePageWithContentInputDto + { + [Required] + [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxTitleLength))] + public string Title { get; set; } + + [Required] + [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxUrlLength))] + public string Url { get; set; } + + [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))] + public string Description { get; set; } + + [Required] + [DynamicMaxLength(typeof(ContentConsts), nameof(ContentConsts.MaxValueLength))] + public string Content { get; set; } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/IPageAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/IPageAppService.cs new file mode 100644 index 0000000000..0b0cf7d182 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/IPageAppService.cs @@ -0,0 +1,20 @@ +using System; +using System.Threading.Tasks; + +namespace Volo.CmsKit.Pages +{ + public interface IPageAppService + { + Task CreatePageAsync(CreatePageInputDto input); + + Task CreatePageWithContentAsync(CreatePageWithContentInputDto input); + + Task UpdatePageAsync(Guid id, UpdatePageInputDto input); + + Task DoesUrlExistAsync(CheckUrlInputDto input); + + Task UpdatePageContentAsync(Guid id, UpdatePageContentInputDto input); + + Task DeletePageAsync(Guid id); + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/PageDto.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/PageDto.cs new file mode 100644 index 0000000000..e2a10d39b5 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/PageDto.cs @@ -0,0 +1,14 @@ +using System; +using Volo.Abp.Application.Dtos; + +namespace Volo.CmsKit.Pages +{ + public class PageDto : EntityDto + { + public string Title { get; set; } + + public string Url { get; set; } + + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/PageWithContentDto.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/PageWithContentDto.cs new file mode 100644 index 0000000000..b9ed14ab0d --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/PageWithContentDto.cs @@ -0,0 +1,17 @@ +using System; +using Volo.Abp.Application.Dtos; +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.Pages +{ + public class PageWithContentDto : EntityDto + { + public string Title { get; set; } + + public string Url { get; set; } + + public string Description { get; set; } + + public ContentDto Content { get; set; } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/UpdatePageContentInputDto.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/UpdatePageContentInputDto.cs new file mode 100644 index 0000000000..ba50ae9f30 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/UpdatePageContentInputDto.cs @@ -0,0 +1,13 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.Pages +{ + public class UpdatePageContentInputDto + { + [Required] + [DynamicMaxLength(typeof(ContentConsts), nameof(ContentConsts.MaxValueLength))] + public string Content { get; set; } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/UpdatePageInputDto.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/UpdatePageInputDto.cs new file mode 100644 index 0000000000..be84b97f4f --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application.Contracts/Volo/CmsKit/Pages/UpdatePageInputDto.cs @@ -0,0 +1,19 @@ +using System.ComponentModel.DataAnnotations; +using Volo.Abp.Validation; + +namespace Volo.CmsKit.Pages +{ + public class UpdatePageInputDto + { + [Required] + [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxTitleLength))] + public string Title { get; set; } + + [Required] + [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxUrlLength))] + public string Url { get; set; } + + [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))] + public string Description { get; set; } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/CmsKitAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/CmsKitAppServiceBase.cs similarity index 100% rename from modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/CmsKitAppService.cs rename to modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/CmsKitAppServiceBase.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/CmsKitCommonApplicationAutoMapperProfile.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/CmsKitCommonApplicationAutoMapperProfile.cs index c7be0fcc69..b0c6388c30 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/CmsKitCommonApplicationAutoMapperProfile.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/CmsKitCommonApplicationAutoMapperProfile.cs @@ -1,8 +1,9 @@ using AutoMapper; using Volo.CmsKit.Contents; +using Volo.CmsKit.Pages; using Volo.CmsKit.Tags; -namespace Volo.CmsKit.Common.Application.Volo.CmsKit +namespace Volo.CmsKit { public class CmsKitCommonApplicationAutoMapperProfile : Profile { @@ -11,6 +12,8 @@ namespace Volo.CmsKit.Common.Application.Volo.CmsKit CreateMap(); CreateMap(); + + CreateMap(); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentAppService.cs index 072a68b38d..c91478dd6a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Contents/ContentAppService.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Volo.CmsKit.Common.Application.Contracts.Volo.CmsKit.Contents; namespace Volo.CmsKit.Contents { diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Pages/PageAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Pages/PageAppService.cs new file mode 100644 index 0000000000..435be73ecd --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Pages/PageAppService.cs @@ -0,0 +1,100 @@ +using System; +using System.Threading; +using System.Threading.Tasks; +using Volo.Abp; +using Volo.CmsKit.Contents; + +namespace Volo.CmsKit.Pages +{ + public class PageAppService : CmsKitAppServiceBase, IPageAppService + { + protected readonly IPageRepository PageRepository; + protected readonly IContentRepository ContentRepository; + + public PageAppService(IPageRepository pageRepository, IContentRepository contentRepository) + { + PageRepository = pageRepository; + ContentRepository = contentRepository; + } + + public virtual async Task CreatePageAsync(CreatePageInputDto input) + { + var page = await CreatePageAsync(input.Title, input.Url, input.Description); + + await PageRepository.InsertAsync(page); + + return ObjectMapper.Map(page); + } + + public virtual async Task CreatePageWithContentAsync(CreatePageWithContentInputDto input) + { + var page = await CreatePageAsync(input.Title, input.Url, input.Description); + + await PageRepository.InsertAsync(page); + + var content = new Content( + GuidGenerator.Create(), + nameof(Page), + page.Id.ToString(), + input.Content, + page.TenantId); + + await ContentRepository.InsertAsync(content); + + return ObjectMapper.Map(page); + } + + public virtual async Task UpdatePageAsync(Guid id, UpdatePageInputDto input) + { + var page = await PageRepository.GetAsync(id); + + if (page.Url != input.Url) + { + await CheckPageUrlAsync(input.Url); + } + + page.Title = input.Title; + page.Url = input.Url; + page.Description = input.Description; + + await PageRepository.UpdateAsync(page); + + return ObjectMapper.Map(page); + } + + public virtual Task DoesUrlExistAsync(CheckUrlInputDto input) + { + return PageRepository.DoesExistAsync(input.Url); + } + + public virtual async Task UpdatePageContentAsync(Guid id, UpdatePageContentInputDto input) + { + var pageContent = await ContentRepository.GetAsync(nameof(Page), id.ToString()); + + pageContent.SetValue(input.Content); + + await ContentRepository.UpdateAsync(pageContent); + } + + public virtual async Task DeletePageAsync(Guid id) + { + await ContentRepository.DeleteAsync(nameof(Page), id.ToString(), CurrentTenant?.Id, CancellationToken.None); + await PageRepository.DeleteAsync(id, cancellationToken: CancellationToken.None); + } + + protected virtual async Task CreatePageAsync(string title, string url, string description) + { + await CheckPageUrlAsync(url); + + return new Page(GuidGenerator.Create(), title, url, description, CurrentTenant?.Id); + } + + protected virtual async Task CheckPageUrlAsync(string url) + { + if (await PageRepository.DoesExistAsync(url)) + { + throw new UserFriendlyException("Url exist"); + } + } + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/Controllers/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/Controllers/Contents/ContentController.cs index 260668e52d..ba108a605c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/Controllers/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.HttpApi/Volo/CmsKit/Controllers/Contents/ContentController.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -using Volo.CmsKit.Common.Application.Contracts.Volo.CmsKit.Contents; using Volo.CmsKit.Contents; namespace Volo.CmsKit.Controllers.Contents diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Shared/Components/Contents/ContentViewComponent.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Shared/Components/Contents/ContentViewComponent.cs index 14522303c6..48a94f827a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Shared/Components/Contents/ContentViewComponent.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Web/Pages/CmsKit/Shared/Components/Contents/ContentViewComponent.cs @@ -7,7 +7,6 @@ using Microsoft.Extensions.Options; using Volo.Abp.AspNetCore.Mvc; using Volo.Abp.AspNetCore.Mvc.UI; using Volo.Abp.AspNetCore.Mvc.UI.Widgets; -using Volo.CmsKit.Common.Application.Contracts.Volo.CmsKit.Contents; using Volo.CmsKit.Contents; using Volo.CmsKit.Web.Contents; diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Pages/PageConsts.cs b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Pages/PageConsts.cs index f0b5032ee7..105566c2bd 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Pages/PageConsts.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Pages/PageConsts.cs @@ -2,10 +2,10 @@ { public class PageConsts { - public const int MaxTitleLength = 256; + public static int MaxTitleLength = 256; - public const int MaxUrlLength = 256; + public static int MaxUrlLength = 256; - public const int MaxDescriptionLength = 515; + public static int MaxDescriptionLength = 515; } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/IPageRepository.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/IPageRepository.cs index 938bbf9cd4..95c09474aa 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/IPageRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/IPageRepository.cs @@ -1,10 +1,15 @@ using System; +using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; namespace Volo.CmsKit.Pages { public interface IPageRepository : IBasicRepository { - + Task GetByUrlAsync(string url); + + Task FindByUrlAsync(string url); + + Task DoesExistAsync(string url); } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs index 0a4dd57cc5..c02617c8d3 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs @@ -12,27 +12,22 @@ namespace Volo.CmsKit.Pages public virtual string Title { get; set; } + public virtual string Url { get; set; } + public virtual string Description { get; set; } - public virtual string Url { get; set; } - protected Page() { } - public Page(Guid id, [NotNull] string title, [CanBeNull] string description, [CanBeNull] string url = null, Guid? tenantId = null) : base(id) + public Page(Guid id, [NotNull] string title, [NotNull] string url, [CanBeNull] string description, Guid? tenantId = null) : base(id) { Title = Check.NotNullOrWhiteSpace(title, nameof(title), PageConsts.MaxTitleLength); + Url = Check.NotNullOrWhiteSpace(url, nameof(url), PageConsts.MaxUrlLength); Description = Check.Length(description, nameof(description), PageConsts.MaxDescriptionLength); - SetUrl(url); TenantId = tenantId; } - - public virtual void SetUrl(string url) - { - Url = Check.Length(url, nameof(url), PageConsts.MaxUrlLength); - } } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs index 9c3b323f45..4502a13b4c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs @@ -1,4 +1,6 @@ using System; +using System.Threading.Tasks; +using Microsoft.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -10,5 +12,20 @@ namespace Volo.CmsKit.Pages public EfCorePageRepository(IDbContextProvider dbContextProvider) : base(dbContextProvider) { } + + public Task GetByUrlAsync(string url) + { + return GetAsync(x => x.Url == url); + } + + public Task FindByUrlAsync(string url) + { + return FindAsync(x => x.Url == url); + } + + public Task DoesExistAsync(string url) + { + return DbSet.AnyAsync(x => x.Url == url); + } } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs index adf3d85dca..e7c6cd32f5 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs @@ -1,4 +1,6 @@ using System; +using System.Threading.Tasks; +using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Pages; @@ -10,5 +12,20 @@ namespace Volo.CmsKit.MongoDB.Pages public MongoPageRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) { } + + public Task GetByUrlAsync(string url) + { + return GetAsync(x => x.Url == url); + } + + public Task FindByUrlAsync(string url) + { + return FindAsync(x => x.Url == url); + } + + public Task DoesExistAsync(string url) + { + return GetMongoQueryable().AnyAsync(x => x.Url == url); + } } } \ No newline at end of file