Browse Source

Merge pull request #7731 from abpframework/cms-kit/pages-prefix

Cms Kit - Pages Prefix
pull/7784/head
İlkay İlknur 6 years ago
committed by GitHub
parent
commit
5c8239007b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      modules/cms-kit/host/Volo.CmsKit.Host.Shared/FeatureConfigurer.cs
  2. 1960
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20210219084931_PageSlugChange.Designer.cs
  3. 46
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20210219084931_PageSlugChange.cs
  4. 3845
      modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs
  5. 4
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/CreatePageInputDto.cs
  6. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/PageDto.cs
  7. 4
      modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/UpdatePageInputDto.cs
  8. 17
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Pages/PageAdminAppService.cs
  9. 2
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs
  10. 4
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json
  11. 2
      modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Pages/PageConsts.cs
  12. 6
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/IPageRepository.cs
  13. 10
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs
  14. 23
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/PageSlugAlreadyExistsException.cs
  15. 23
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/PageUrlAlreadyExistException.cs
  16. 4
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs
  17. 12
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs
  18. 12
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs
  19. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/IPagePublicAppService.cs
  20. 2
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/PageDto.cs
  21. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs
  22. 6
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Pages/PagesPublicController.cs
  23. 8
      modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs
  24. 37
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Controllers/PageController.cs
  25. 13
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Pages/Index.cshtml
  26. 34
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Pages/Index.cshtml.cs
  27. 6
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Shared/Components/Pages/DefaultPageViewComponent.cs
  28. 9
      modules/cms-kit/src/Volo.CmsKit.Public.Web/Views/Page/Index.cshtml
  29. 2
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Blogs/BlogPostAdminAppService_Tests.cs
  30. 18
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Pages/PageAdminAppService_Tests.cs
  31. 4
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Pages/PagePublicAppService_Tests.cs
  32. 4
      modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs
  33. 4
      modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs
  34. 8
      modules/cms-kit/test/Volo.CmsKit.TestBase/Pages/PageRepository_Test.cs

1
modules/cms-kit/host/Volo.CmsKit.Host.Shared/FeatureConfigurer.cs

@ -13,7 +13,6 @@ namespace Volo.CmsKit
OneTimeRunner.Run(() => OneTimeRunner.Run(() =>
{ {
GlobalFeatureManager.Instance.Modules.CmsKit().EnableAll(); GlobalFeatureManager.Instance.Modules.CmsKit().EnableAll();
GlobalFeatureManager.Instance.Modules.CmsKit().Disable<PagesFeature>();
}); });
} }
} }

1960
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20210219084931_PageSlugChange.Designer.cs

File diff suppressed because it is too large

46
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/20210219084931_PageSlugChange.cs

@ -0,0 +1,46 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
namespace Volo.CmsKit.Migrations
{
public partial class PageSlugChange : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "CmsPages",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
TenantId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
Title = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
Slug = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: false),
Description = table.Column<string>(type: "nvarchar(512)", maxLength: 512, nullable: true),
ExtraProperties = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(40)", maxLength: 40, nullable: true),
CreationTime = table.Column<DateTime>(type: "datetime2", nullable: false),
CreatorId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
LastModificationTime = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifierId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false, defaultValue: false),
DeleterId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
DeletionTime = table.Column<DateTime>(type: "datetime2", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_CmsPages", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_CmsPages_TenantId_Slug",
table: "CmsPages",
columns: new[] { "TenantId", "Slug" });
}
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "CmsPages");
}
}
}

3845
modules/cms-kit/host/Volo.CmsKit.Web.Unified/Migrations/UnifiedDbContextModelSnapshot.cs

File diff suppressed because it is too large

4
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/CreatePageInputDto.cs

@ -12,8 +12,8 @@ namespace Volo.CmsKit.Admin.Pages
public string Title { get; set; } public string Title { get; set; }
[Required] [Required]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxUrlLength))] [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Url { get; set; } public string Slug { get; set; }
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))] [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))]
public string Description { get; set; } public string Description { get; set; }

2
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/PageDto.cs

@ -7,7 +7,7 @@ namespace Volo.CmsKit.Admin.Pages
{ {
public string Title { get; set; } public string Title { get; set; }
public string Url { get; set; } public string Slug { get; set; }
public string Description { get; set; } public string Description { get; set; }
} }

4
modules/cms-kit/src/Volo.CmsKit.Admin.Application.Contracts/Volo/CmsKit/Admin/Pages/UpdatePageInputDto.cs

@ -12,8 +12,8 @@ namespace Volo.CmsKit.Admin.Pages
public string Title { get; set; } public string Title { get; set; }
[Required] [Required]
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxUrlLength))] [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxSlugLength))]
public string Url { get; set; } public string Slug { get; set; }
[DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))] [DynamicMaxLength(typeof(PageConsts), nameof(PageConsts.MaxDescriptionLength))]
public string Description { get; set; } public string Description { get; set; }

17
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Pages/PageAdminAppService.cs

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using AutoMapper;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Dtos;
using Volo.Abp.GlobalFeatures; using Volo.Abp.GlobalFeatures;
@ -47,9 +48,9 @@ namespace Volo.CmsKit.Admin.Pages
[Authorize(CmsKitAdminPermissions.Pages.Create)] [Authorize(CmsKitAdminPermissions.Pages.Create)]
public virtual async Task<PageDto> CreateAsync(CreatePageInputDto input) public virtual async Task<PageDto> CreateAsync(CreatePageInputDto input)
{ {
await CheckPageUrlAsync(input.Url); await CheckPageSlugAsync(input.Slug);
var page = new Page(GuidGenerator.Create(), input.Title, input.Url, input.Description, CurrentTenant?.Id); var page = new Page(GuidGenerator.Create(), input.Title, input.Slug, input.Description, CurrentTenant?.Id);
await PageRepository.InsertAsync(page); await PageRepository.InsertAsync(page);
@ -61,13 +62,13 @@ namespace Volo.CmsKit.Admin.Pages
{ {
var page = await PageRepository.GetAsync(id); var page = await PageRepository.GetAsync(id);
if (page.Url != input.Url) if (page.Slug != input.Slug)
{ {
await CheckPageUrlAsync(input.Url); await CheckPageSlugAsync(input.Slug);
} }
page.SetTitle(input.Title); page.SetTitle(input.Title);
page.SetUrl(input.Url); page.SetSlug(input.Slug);
page.Description = input.Description; page.Description = input.Description;
await PageRepository.UpdateAsync(page); await PageRepository.UpdateAsync(page);
@ -81,11 +82,11 @@ namespace Volo.CmsKit.Admin.Pages
await PageRepository.DeleteAsync(id); await PageRepository.DeleteAsync(id);
} }
protected virtual async Task CheckPageUrlAsync(string url) protected virtual async Task CheckPageSlugAsync(string slug)
{ {
if (await PageRepository.ExistsAsync(url)) if (await PageRepository.ExistsAsync(slug))
{ {
throw new PageUrlAlreadyExistException(url); throw new PageSlugAlreadyExistsException(slug);
} }
} }
} }

2
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/CmsKitErrorCodes.cs

@ -12,7 +12,7 @@
public static class Pages public static class Pages
{ {
public const string UrlAlreadyExist = "CmsKit:Page:0001"; public const string SlugAlreadyExist = "CmsKit:Page:0001";
} }
public static class Blogs public static class Blogs

4
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Localization/Resources/en.json

@ -3,8 +3,8 @@
"texts": { "texts": {
"CmsKit:0002": "Content already exists!", "CmsKit:0002": "Content already exists!",
"CmsKit:0003": "The entity {0} is not taggable.", "CmsKit:0003": "The entity {0} is not taggable.",
"CmsKit:BlogPost:0001": "Same url slug already exists!", "CmsKit:BlogPost:0001": "The given slug already exists!",
"CmsKit:Page:0001": "The given url ({0}) already exists.", "CmsKit:Page:0001": "The given slug ({0}) already exists.",
"CmsKit:Tag:0002": "The entity is not taggable!", "CmsKit:Tag:0002": "The entity is not taggable!",
"CommentAuthorizationExceptionMessage": "Those comments are not allowed for public display.", "CommentAuthorizationExceptionMessage": "Those comments are not allowed for public display.",
"Comments": "Comments", "Comments": "Comments",

2
modules/cms-kit/src/Volo.CmsKit.Domain.Shared/Volo/CmsKit/Pages/PageConsts.cs

@ -4,7 +4,7 @@
{ {
public static int MaxTitleLength { get; set; } = 256; public static int MaxTitleLength { get; set; } = 256;
public static int MaxUrlLength { get; set; } = 256; public static int MaxSlugLength { get; set; } = 256;
public static int MaxDescriptionLength { get; set; } = 512; public static int MaxDescriptionLength { get; set; } = 512;
} }

6
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/IPageRepository.cs

@ -17,10 +17,10 @@ namespace Volo.CmsKit.Pages
string sorting = null, string sorting = null,
CancellationToken cancellationToken = default); CancellationToken cancellationToken = default);
Task<Page> GetByUrlAsync(string url, CancellationToken cancellationToken = default); Task<Page> GetBySlugAsync(string slug, CancellationToken cancellationToken = default);
Task<Page> FindByUrlAsync(string url, CancellationToken cancellationToken = default); Task<Page> FindBySlugAsync(string slug, CancellationToken cancellationToken = default);
Task<bool> ExistsAsync(string url, CancellationToken cancellationToken = default); Task<bool> ExistsAsync(string slug, CancellationToken cancellationToken = default);
} }
} }

10
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs

@ -12,7 +12,7 @@ namespace Volo.CmsKit.Pages
[NotNull] public virtual string Title { get; protected set; } [NotNull] public virtual string Title { get; protected set; }
[NotNull] public virtual string Url { get; protected set; } [NotNull] public virtual string Slug { get; protected set; }
[CanBeNull] public virtual string Description { get; set; } [CanBeNull] public virtual string Description { get; set; }
@ -20,11 +20,11 @@ namespace Volo.CmsKit.Pages
{ {
} }
public Page(Guid id, [NotNull] string title, [NotNull] string url, [CanBeNull] string description = null, public Page(Guid id, [NotNull] string title, [NotNull] string slug, [CanBeNull] string description = null,
Guid? tenantId = null) : base(id) Guid? tenantId = null) : base(id)
{ {
Title = Check.NotNullOrEmpty(title, nameof(title), PageConsts.MaxTitleLength); Title = Check.NotNullOrEmpty(title, nameof(title), PageConsts.MaxTitleLength);
Url = Check.NotNullOrEmpty(url, nameof(url), PageConsts.MaxUrlLength); Slug = Check.NotNullOrEmpty(slug, nameof(slug), PageConsts.MaxSlugLength);
Description = Check.Length(description, nameof(description), PageConsts.MaxDescriptionLength); Description = Check.Length(description, nameof(description), PageConsts.MaxDescriptionLength);
TenantId = tenantId; TenantId = tenantId;
@ -35,9 +35,9 @@ namespace Volo.CmsKit.Pages
Title = Check.NotNullOrEmpty(title, nameof(title), PageConsts.MaxTitleLength); Title = Check.NotNullOrEmpty(title, nameof(title), PageConsts.MaxTitleLength);
} }
public virtual void SetUrl(string url) public virtual void SetSlug(string slug)
{ {
Url = Check.NotNullOrEmpty(url, nameof(url), PageConsts.MaxUrlLength); Slug = Check.NotNullOrEmpty(slug, nameof(slug), PageConsts.MaxSlugLength);
} }
} }
} }

23
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/PageSlugAlreadyExistsException.cs

@ -0,0 +1,23 @@
using System;
using System.Runtime.Serialization;
using JetBrains.Annotations;
using Volo.Abp;
namespace Volo.CmsKit.Pages
{
[Serializable]
public class PageSlugAlreadyExistsException : BusinessException
{
public PageSlugAlreadyExistsException([NotNull] string slug)
{
Code = CmsKitErrorCodes.Pages.SlugAlreadyExist;
WithData(nameof(Page.Slug), slug);
}
public PageSlugAlreadyExistsException(SerializationInfo serializationInfo, StreamingContext context)
: base(serializationInfo, context)
{
}
}
}

23
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/PageUrlAlreadyExistException.cs

@ -1,23 +0,0 @@
using System;
using System.Runtime.Serialization;
using JetBrains.Annotations;
using Volo.Abp;
namespace Volo.CmsKit.Pages
{
[Serializable]
public class PageUrlAlreadyExistException : BusinessException
{
public PageUrlAlreadyExistException([NotNull] string url)
{
Code = CmsKitErrorCodes.Pages.UrlAlreadyExist;
WithData(nameof(Page.Url), url);
}
public PageUrlAlreadyExistException(SerializationInfo serializationInfo, StreamingContext context)
: base(serializationInfo, context)
{
}
}
}

4
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/EntityFrameworkCore/CmsKitDbContextModelCreatingExtensions.cs

@ -178,10 +178,10 @@ namespace Volo.CmsKit.EntityFrameworkCore
b.ConfigureByConvention(); b.ConfigureByConvention();
b.Property(x => x.Title).IsRequired().HasMaxLength(PageConsts.MaxTitleLength); b.Property(x => x.Title).IsRequired().HasMaxLength(PageConsts.MaxTitleLength);
b.Property(x => x.Url).IsRequired().HasMaxLength(PageConsts.MaxUrlLength); b.Property(x => x.Slug).IsRequired().HasMaxLength(PageConsts.MaxSlugLength);
b.Property(x => x.Description).HasMaxLength(PageConsts.MaxDescriptionLength); b.Property(x => x.Description).HasMaxLength(PageConsts.MaxDescriptionLength);
b.HasIndex(x => new { x.TenantId, x.Url }); b.HasIndex(x => new { x.TenantId, Url = x.Slug });
}); });
} }
else else

12
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs

@ -43,19 +43,19 @@ namespace Volo.CmsKit.Pages
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual Task<Page> GetByUrlAsync(string url, CancellationToken cancellationToken = default) public virtual Task<Page> GetBySlugAsync(string slug, CancellationToken cancellationToken = default)
{ {
return GetAsync(x => x.Url == url, cancellationToken: GetCancellationToken(cancellationToken)); return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual Task<Page> FindByUrlAsync(string url, CancellationToken cancellationToken = default) public virtual Task<Page> FindBySlugAsync(string slug, CancellationToken cancellationToken = default)
{ {
return FindAsync(x => x.Url == url, cancellationToken: GetCancellationToken(cancellationToken)); return FindAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual async Task<bool> ExistsAsync(string url, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync(string slug, CancellationToken cancellationToken = default)
{ {
return await (await GetDbSetAsync()).AnyAsync(x => x.Url == url, GetCancellationToken(cancellationToken)); return await (await GetDbSetAsync()).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken));
} }
} }
} }

12
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs

@ -51,19 +51,19 @@ namespace Volo.CmsKit.MongoDB.Pages
.ToListAsync(cancellation); .ToListAsync(cancellation);
} }
public virtual Task<Page> GetByUrlAsync(string url, CancellationToken cancellationToken = default) public virtual Task<Page> GetBySlugAsync(string slug, CancellationToken cancellationToken = default)
{ {
return GetAsync(x => x.Url == url, cancellationToken: GetCancellationToken(cancellationToken)); return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual Task<Page> FindByUrlAsync(string url, CancellationToken cancellationToken = default) public virtual Task<Page> FindBySlugAsync(string slug, CancellationToken cancellationToken = default)
{ {
return FindAsync(x => x.Url == url, cancellationToken: GetCancellationToken(cancellationToken)); return FindAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual async Task<bool> ExistsAsync(string url, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync(string slug, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.Url == url, GetCancellationToken(cancellationToken)); return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken));
} }
} }
} }

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

@ -5,6 +5,6 @@ namespace Volo.CmsKit.Public.Pages
{ {
public interface IPagePublicAppService public interface IPagePublicAppService
{ {
Task<PageDto> FindByUrlAsync([NotNull] string url); Task<PageDto> FindBySlugAsync([NotNull] string slug);
} }
} }

2
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/PageDto.cs

@ -7,6 +7,6 @@ namespace Volo.CmsKit.Public.Pages
{ {
public string Title { get; set; } public string Title { get; set; }
public string Url { get; set; } public string Slug { get; set; }
} }
} }

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

@ -12,10 +12,10 @@ namespace Volo.CmsKit.Public.Pages
PageRepository = pageRepository; PageRepository = pageRepository;
} }
public virtual async Task<PageDto> FindByUrlAsync(string url) public virtual async Task<PageDto> FindBySlugAsync(string slug)
{ {
PageDto pageDto = null; PageDto pageDto = null;
var page = await PageRepository.FindByUrlAsync(url); var page = await PageRepository.FindBySlugAsync(slug);
if (page !=null) if (page !=null)
{ {

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

@ -20,10 +20,10 @@ namespace Volo.CmsKit.Public.Pages
} }
[HttpGet] [HttpGet]
[Route("url/{url}")] [Route("{slug}")]
public virtual Task<PageDto> FindByUrlAsync(string url) public virtual Task<PageDto> FindBySlugAsync(string slug)
{ {
return PageAppService.FindByUrlAsync(url); return PageAppService.FindBySlugAsync(slug);
} }
} }
} }

8
modules/cms-kit/src/Volo.CmsKit.Public.Web/CmsKitPublicWebModule.cs

@ -59,9 +59,13 @@ namespace Volo.CmsKit.Public.Web
public override void PostConfigureServices(ServiceConfigurationContext context) public override void PostConfigureServices(ServiceConfigurationContext context)
{ {
Configure<RazorPagesOptions>(options => if (GlobalFeatureManager.Instance.IsEnabled<PagesFeature>())
{ {
}); Configure<RazorPagesOptions>(options =>
{
options.Conventions.AddPageRoute("/CmsKit/Pages/Index", @"/pages/{slug:minlength(1)}");
});
}
} }
} }
} }

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

@ -1,37 +0,0 @@
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.ActionConstraints;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.GlobalFeatures;
using Volo.CmsKit.Public.Pages;
namespace Volo.CmsKit.Public.Web.Controllers
{
[RequiresGlobalFeature(typeof(PagesFeature))]
public class PageController : CmsKitPublicControllerBase
{
protected IPagePublicAppService PageAppService { get; }
public PageController(IPagePublicAppService pageAppService)
{
PageAppService = pageAppService;
}
//[HttpGet("/{*url}", Order = int.MaxValue)]
public async Task<IActionResult> IndexAsync(string url)
{
var page = await PageAppService.FindByUrlAsync(url);
if (page == null)
{
return NotFound();
}
return View("~/Views/Page/Index.cshtml", page);
}
}
}

13
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Pages/Index.cshtml

@ -0,0 +1,13 @@
@page
@using Microsoft.AspNetCore.Mvc.Localization
@using Volo.CmsKit.Localization
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
@model Volo.CmsKit.Public.Web.Pages.CmsKit.Pages.IndexModel
@inject IHtmlLocalizer<CmsKitResource> L
@await Component.InvokeAsync(typeof(DefaultPageViewComponent),
new
{
pageId = Model.Page.Id,
title = Model.Page.Title
})

34
modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/CmsKit/Pages/Index.cshtml.cs

@ -0,0 +1,34 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Volo.CmsKit.Public.Pages;
using Volo.CmsKit.Web.Pages;
namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Pages
{
public class IndexModel : CommonPageModel
{
[BindProperty(SupportsGet = true)]
public string Slug { get; set; }
protected IPagePublicAppService PagePublicAppService { get; }
public PageDto Page;
public IndexModel(IPagePublicAppService pagePublicAppService)
{
PagePublicAppService = pagePublicAppService;
}
public async Task<IActionResult> OnGetAsync()
{
Page = await PagePublicAppService.FindBySlugAsync(Slug);
if (Page == null)
{
return NotFound();
}
return Page();
}
}
}

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

@ -9,11 +9,11 @@ namespace Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
[ViewComponent(Name = "CmsDefaultPage")] [ViewComponent(Name = "CmsDefaultPage")]
public class DefaultPageViewComponent : AbpViewComponent public class DefaultPageViewComponent : AbpViewComponent
{ {
protected readonly IPagePublicAppService PageAppService; protected IPagePublicAppService PagePublicAppService { get; }
public DefaultPageViewComponent(IPagePublicAppService pageAppService) public DefaultPageViewComponent(IPagePublicAppService pagePublicAppService)
{ {
PageAppService = pageAppService; PagePublicAppService = pagePublicAppService;
} }
public virtual async Task<IViewComponentResult> InvokeAsync(Guid pageId, string title, string description) public virtual async Task<IViewComponentResult> InvokeAsync(Guid pageId, string title, string description)

9
modules/cms-kit/src/Volo.CmsKit.Public.Web/Views/Page/Index.cshtml

@ -1,9 +0,0 @@
@model Volo.CmsKit.Public.Pages.PageDto
@using Volo.CmsKit.Public.Web.Pages.CmsKit.Shared.Components.Pages
@await Component.InvokeAsync(typeof(DefaultPageViewComponent), new
{
pageId = Model.Id,
title = Model.Title
})

2
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Blogs/BlogPostAdminAppService_Tests.cs

@ -114,7 +114,7 @@ namespace Volo.CmsKit.Blogs
{ {
var nonExistingSlug = "any-other-url"; var nonExistingSlug = "any-other-url";
var exception = await Should.ThrowAsync<EntityNotFoundException>(async () => var exception = await Should.ThrowAsync<EntityNotFoundException>(async () =>
await blogPostAdminAppService.GetBySlugAsync(nonExistingSlug, cmsKitTestData.Page_1_Url)); await blogPostAdminAppService.GetBySlugAsync(nonExistingSlug, cmsKitTestData.Page_1_Slug));
exception.EntityType.ShouldBe(typeof(Blog)); exception.EntityType.ShouldBe(typeof(Blog));
} }

18
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Pages/PageAdminAppService_Tests.cs

@ -64,12 +64,12 @@ namespace Volo.CmsKit.Pages
var dto = new CreatePageInputDto var dto = new CreatePageInputDto
{ {
Title = "test", Title = "test",
Url = "test-url" Slug = "test-url"
}; };
await Should.NotThrowAsync(async () => await _pageAdminAppService.CreateAsync(dto)); await Should.NotThrowAsync(async () => await _pageAdminAppService.CreateAsync(dto));
var page = await _pageRepository.GetByUrlAsync(dto.Url); var page = await _pageRepository.GetBySlugAsync(dto.Slug);
page.Title.ShouldBe(dto.Title); page.Title.ShouldBe(dto.Title);
} }
@ -80,12 +80,12 @@ namespace Volo.CmsKit.Pages
var dto = new CreatePageInputDto var dto = new CreatePageInputDto
{ {
Title = "test", Title = "test",
Url = _data.Page_1_Url Slug = _data.Page_1_Slug
}; };
var exception = await Should.ThrowAsync<PageUrlAlreadyExistException>(async () => await _pageAdminAppService.CreateAsync(dto)); var exception = await Should.ThrowAsync<PageSlugAlreadyExistsException>(async () => await _pageAdminAppService.CreateAsync(dto));
exception.Code.ShouldBe(CmsKitErrorCodes.Pages.UrlAlreadyExist); exception.Code.ShouldBe(CmsKitErrorCodes.Pages.SlugAlreadyExist);
} }
[Fact] [Fact]
@ -95,7 +95,7 @@ namespace Volo.CmsKit.Pages
{ {
Title = _data.Page_1_Title + "++", Title = _data.Page_1_Title + "++",
Description = "new description", Description = "new description",
Url = _data.Page_1_Url+ "test" Slug = _data.Page_1_Slug+ "test"
}; };
await Should.NotThrowAsync(async () => await _pageAdminAppService.UpdateAsync(_data.Page_1_Id, dto)); await Should.NotThrowAsync(async () => await _pageAdminAppService.UpdateAsync(_data.Page_1_Id, dto));
@ -105,8 +105,8 @@ namespace Volo.CmsKit.Pages
updatedPage.Title.ShouldNotBe(_data.Page_1_Title); updatedPage.Title.ShouldNotBe(_data.Page_1_Title);
updatedPage.Title.ShouldBe(dto.Title); updatedPage.Title.ShouldBe(dto.Title);
updatedPage.Url.ShouldNotBe(_data.Page_1_Url); updatedPage.Slug.ShouldNotBe(_data.Page_1_Slug);
updatedPage.Url.ShouldBe(dto.Url); updatedPage.Slug.ShouldBe(dto.Slug);
updatedPage.Description.ShouldNotBe(_data.Page_1_Description); updatedPage.Description.ShouldNotBe(_data.Page_1_Description);
updatedPage.Description.ShouldBe(dto.Description); updatedPage.Description.ShouldBe(dto.Description);
@ -119,7 +119,7 @@ namespace Volo.CmsKit.Pages
{ {
Title = _data.Page_1_Title + "++", Title = _data.Page_1_Title + "++",
Description = "new description", Description = "new description",
Url = _data.Page_2_Url Slug = _data.Page_2_Slug
}; };
await Should.ThrowAsync<Exception>(async () => await _pageAdminAppService.UpdateAsync(_data.Page_1_Id, dto)); await Should.ThrowAsync<Exception>(async () => await _pageAdminAppService.UpdateAsync(_data.Page_1_Id, dto));

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

@ -20,7 +20,7 @@ namespace Volo.CmsKit.Pages
[Fact] [Fact]
public async Task ShouldFindByUrlAsync() public async Task ShouldFindByUrlAsync()
{ {
var page = await _pageAppService.FindByUrlAsync(_data.Page_1_Url); var page = await _pageAppService.FindBySlugAsync(_data.Page_1_Slug);
page.ShouldNotBeNull(); page.ShouldNotBeNull();
page.Title.ShouldBe(_data.Page_1_Title); page.Title.ShouldBe(_data.Page_1_Title);
@ -29,7 +29,7 @@ namespace Volo.CmsKit.Pages
[Fact] [Fact]
public async Task ShouldNotGetByUrlAsync() public async Task ShouldNotGetByUrlAsync()
{ {
var page = await _pageAppService.FindByUrlAsync("not-exist-url"); var page = await _pageAppService.FindBySlugAsync("not-exist-url");
page.ShouldBeNull(); page.ShouldBeNull();
} }

4
modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitDataSeedContributor.cs

@ -305,13 +305,13 @@ namespace Volo.CmsKit
private async Task SeedPagesAsync() private async Task SeedPagesAsync()
{ {
var page1 = new Page(_cmsKitTestData.Page_1_Id, _cmsKitTestData.Page_1_Title, _cmsKitTestData.Page_1_Url, _cmsKitTestData.Page_1_Description); var page1 = new Page(_cmsKitTestData.Page_1_Id, _cmsKitTestData.Page_1_Title, _cmsKitTestData.Page_1_Slug, _cmsKitTestData.Page_1_Description);
var page1Content = new Content(_guidGenerator.Create(), nameof(Page), page1.Id.ToString(), _cmsKitTestData.Page_1_Content); var page1Content = new Content(_guidGenerator.Create(), nameof(Page), page1.Id.ToString(), _cmsKitTestData.Page_1_Content);
await _pageRepository.InsertAsync(page1); await _pageRepository.InsertAsync(page1);
await _contentRepository.InsertAsync(page1Content); await _contentRepository.InsertAsync(page1Content);
var page2 = new Page(_cmsKitTestData.Page_2_Id, _cmsKitTestData.Page_2_Title, _cmsKitTestData.Page_2_Url, _cmsKitTestData.Page_2_Description); var page2 = new Page(_cmsKitTestData.Page_2_Id, _cmsKitTestData.Page_2_Title, _cmsKitTestData.Page_2_Slug, _cmsKitTestData.Page_2_Description);
var page2Content = new Content(_guidGenerator.Create(), nameof(Page), page2.Id.ToString(), _cmsKitTestData.Page_2_Content); var page2Content = new Content(_guidGenerator.Create(), nameof(Page), page2.Id.ToString(), _cmsKitTestData.Page_2_Content);
await _pageRepository.InsertAsync(page2); await _pageRepository.InsertAsync(page2);

4
modules/cms-kit/test/Volo.CmsKit.TestBase/CmsKitTestData.cs

@ -45,7 +45,7 @@ namespace Volo.CmsKit
public string Page_1_Title { get; } = "Imagine Dragons - Believer Lyrics"; public string Page_1_Title { get; } = "Imagine Dragons - Believer Lyrics";
public string Page_1_Url { get; } = "imagine-dragons-believer-lyrics"; public string Page_1_Slug { get; } = "imagine-dragons-believer-lyrics";
public string Page_1_Description { get; } = "You can get the lyrics of the music."; public string Page_1_Description { get; } = "You can get the lyrics of the music.";
@ -55,7 +55,7 @@ namespace Volo.CmsKit
public string Page_2_Title { get; } = "Imagine Dragons - Believer Lyrics (Page 2)"; public string Page_2_Title { get; } = "Imagine Dragons - Believer Lyrics (Page 2)";
public string Page_2_Url { get; } = "imagine-dragons-believer-lyrics-2"; public string Page_2_Slug { get; } = "imagine-dragons-believer-lyrics-2";
public string Page_2_Description { get; } = "You can get the lyrics of the music."; public string Page_2_Description { get; } = "You can get the lyrics of the music.";

8
modules/cms-kit/test/Volo.CmsKit.TestBase/Pages/PageRepository_Test.cs

@ -53,7 +53,7 @@ namespace Volo.CmsKit.Pages
[Fact] [Fact]
public async Task ShouldGetByUrlAsync() public async Task ShouldGetByUrlAsync()
{ {
var page = await _pageRepository.GetByUrlAsync(_cmsKitTestData.Page_1_Url); var page = await _pageRepository.GetBySlugAsync(_cmsKitTestData.Page_1_Slug);
page.ShouldNotBeNull(); page.ShouldNotBeNull();
page.Description.ShouldBe(_cmsKitTestData.Page_1_Description); page.Description.ShouldBe(_cmsKitTestData.Page_1_Description);
@ -62,7 +62,7 @@ namespace Volo.CmsKit.Pages
[Fact] [Fact]
public async Task ShouldFindByUrlAsync() public async Task ShouldFindByUrlAsync()
{ {
var page = await _pageRepository.FindByUrlAsync(_cmsKitTestData.Page_1_Url); var page = await _pageRepository.FindBySlugAsync(_cmsKitTestData.Page_1_Slug);
page.ShouldNotBeNull(); page.ShouldNotBeNull();
page.Description.ShouldBe(_cmsKitTestData.Page_1_Description); page.Description.ShouldBe(_cmsKitTestData.Page_1_Description);
@ -71,7 +71,7 @@ namespace Volo.CmsKit.Pages
[Fact] [Fact]
public async Task ShouldNotFindByUrlAsync() public async Task ShouldNotFindByUrlAsync()
{ {
var page = await _pageRepository.FindByUrlAsync("not-exist-lyrics"); var page = await _pageRepository.FindBySlugAsync("not-exist-lyrics");
page.ShouldBeNull(); page.ShouldBeNull();
} }
@ -79,7 +79,7 @@ namespace Volo.CmsKit.Pages
[Fact] [Fact]
public async Task ShouldBeExistAsync() public async Task ShouldBeExistAsync()
{ {
var page = await _pageRepository.ExistsAsync(_cmsKitTestData.Page_1_Url); var page = await _pageRepository.ExistsAsync(_cmsKitTestData.Page_1_Slug);
page.ShouldBeTrue(); page.ShouldBeTrue();
} }

Loading…
Cancel
Save