diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/PageManager.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/PageManager.cs index c11a64689a..587ae91144 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/PageManager.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/PageManager.cs @@ -37,7 +37,7 @@ public class PageManager : DomainService CurrentTenant.Id); } - public virtual async Task SetSlugAsync(Page page, string newSlug) + public virtual async Task SetSlugAsync(Page page, [NotNull] string newSlug) { if (page.Slug != newSlug) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/IPagePublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/IPagePublicAppService.cs index bec4261f19..93ebb3df38 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/IPagePublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Pages/IPagePublicAppService.cs @@ -8,5 +8,6 @@ namespace Volo.CmsKit.Public.Pages; public interface IPagePublicAppService : IApplicationService { Task FindBySlugAsync([NotNull] string slug); + Task DoesSlugExistAsync([NotNull] string slug); Task FindDefaultHomePageAsync(); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs index 9940dceab1..85be369bb1 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Pages/PagePublicAppService.cs @@ -1,5 +1,6 @@ using System; using System.Threading.Tasks; +using JetBrains.Annotations; using Microsoft.Extensions.Caching.Distributed; using Volo.Abp.Caching; using Volo.Abp.Features; @@ -57,4 +58,9 @@ public class PagePublicAppService : CmsKitPublicAppServiceBase, IPagePublicAppSe return ObjectMapper.Map(pageCacheItem); } + + public Task DoesSlugExistAsync([NotNull] string slug) + { + return PageRepository.ExistsAsync(slug); + } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/Pages/PagesPublicClientProxy.Generated.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/Pages/PagesPublicClientProxy.Generated.cs index 6a7df3e4e2..4fb1e8bc9f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/Pages/PagesPublicClientProxy.Generated.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/Volo/CmsKit/Public/Pages/PagesPublicClientProxy.Generated.cs @@ -30,4 +30,12 @@ public partial class PagesPublicClientProxy : ClientProxyBase(nameof(FindDefaultHomePageAsync)); } + + public virtual async Task DoesSlugExistAsync(string slug) + { + return await RequestAsync(nameof(DoesSlugExistAsync), new ClientProxyRequestTypeValue + { + { typeof(string), slug } + }); + } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json index bfde04ba1d..bc020e6768 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi.Client/ClientProxies/cms-kit-generate-proxy.json @@ -829,6 +829,23 @@ "typeSimple": "Volo.CmsKit.Contents.PageDto" } }, + { + "name": "DoesSlugExistAsync", + "parametersOnMethod": [ + { + "name": "slug", + "typeAsString": "System.String, System.Private.CoreLib", + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "returnValue": { + "type": "System.Boolean", + "typeSimple": "boolean" + } + }, { "name": "FindDefaultHomePageAsync", "parametersOnMethod": [], @@ -892,6 +909,43 @@ }, "allowAnonymous": null, "implementFrom": "Volo.CmsKit.Public.Pages.IPagePublicAppService" + }, + "DoesSlugExistAsyncBySlug": { + "uniqueName": "DoesSlugExistAsyncBySlug", + "name": "DoesSlugExistAsync", + "httpMethod": "GET", + "url": "api/cms-kit-public/pages/{slug}/exist", + "supportedVersions": [], + "parametersOnMethod": [ + { + "name": "slug", + "typeAsString": "System.String, System.Private.CoreLib", + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null + } + ], + "parameters": [ + { + "nameOnMethod": "slug", + "name": "slug", + "jsonName": null, + "type": "System.String", + "typeSimple": "string", + "isOptional": false, + "defaultValue": null, + "constraintTypes": [], + "bindingSourceId": "Path", + "descriptorName": "" + } + ], + "returnValue": { + "type": "System.Boolean", + "typeSimple": "boolean" + }, + "allowAnonymous": null, + "implementFrom": "Volo.CmsKit.Public.Pages.IPagePublicAppService" } } }, diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Pages/PagesPublicController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Pages/PagesPublicController.cs index d6550977ef..53608dee21 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Pages/PagesPublicController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Pages/PagesPublicController.cs @@ -1,4 +1,5 @@ using System.Threading.Tasks; +using JetBrains.Annotations; using Microsoft.AspNetCore.Mvc; using Volo.Abp; using Volo.Abp.Features; @@ -35,4 +36,11 @@ public class PagesPublicController : CmsKitPublicControllerBase, IPagePublicAppS { return PageAppService.FindDefaultHomePageAsync(); } + + [HttpGet] + [Route("{slug}/exist")] + public Task DoesSlugExistAsync([NotNull] string slug) + { + return PageAppService.DoesSlugExistAsync(slug); + } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/PageRoutingMiddleware.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/PageRoutingMiddleware.cs index 2298f5a1d7..bf1d62e845 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/PageRoutingMiddleware.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/PageRoutingMiddleware.cs @@ -25,12 +25,12 @@ public class PageRoutingMiddleware : IMiddleware, ITransientDependency var pagePublicAppService = context.RequestServices.GetRequiredService(); - var page = await pagePublicAppService.FindBySlugAsync( - context.Request.Path.ToString().TrimStart('/')); + var slug = context.Request.Path.ToString().TrimStart('/'); + var exist = await pagePublicAppService.DoesSlugExistAsync(slug); - if (page is not null) + if (exist) { - context.Request.Path = $"/pages/{page.Slug}"; + context.Request.Path = $"/pages/{slug}"; await next(context); }