Check if page exist before openning it

pull/17642/head
Enis Necipoglu 1 year ago
parent 78de5d602f
commit e0c6bb33e0
No known key found for this signature in database
GPG Key ID: 1EC55E13241E1680

@ -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)
{

@ -8,5 +8,6 @@ namespace Volo.CmsKit.Public.Pages;
public interface IPagePublicAppService : IApplicationService
{
Task<PageDto> FindBySlugAsync([NotNull] string slug);
Task<bool> DoesSlugExistAsync([NotNull] string slug);
Task<PageDto> FindDefaultHomePageAsync();
}

@ -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, PageDto>(pageCacheItem);
}
public Task<bool> DoesSlugExistAsync([NotNull] string slug)
{
return PageRepository.ExistsAsync(slug);
}
}

@ -30,4 +30,12 @@ public partial class PagesPublicClientProxy : ClientProxyBase<IPagePublicAppServ
{
return await RequestAsync<PageDto>(nameof(FindDefaultHomePageAsync));
}
public virtual async Task<bool> DoesSlugExistAsync(string slug)
{
return await RequestAsync<bool>(nameof(DoesSlugExistAsync), new ClientProxyRequestTypeValue
{
{ typeof(string), slug }
});
}
}

@ -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"
}
}
},

@ -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<bool> DoesSlugExistAsync([NotNull] string slug)
{
return PageAppService.DoesSlugExistAsync(slug);
}
}

@ -25,12 +25,12 @@ public class PageRoutingMiddleware : IMiddleware, ITransientDependency
var pagePublicAppService = context.RequestServices.GetRequiredService<IPagePublicAppService>();
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);
}

Loading…
Cancel
Save