CmsKit - Add Existence check for blog

pull/7226/head
enisn 5 years ago
parent ca9c92b895
commit f228768ee8

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.Domain.Entities;
using Volo.Abp.Domain.Services;
namespace Volo.CmsKit.Blogs
@ -48,7 +49,8 @@ namespace Volo.CmsKit.Blogs
private async Task CheckBlogExistenceAsync(Guid blogId)
{
await blogRepository.GetAsync(blogId);
if (!await blogRepository.ExistsAsync(blogId))
throw new EntityNotFoundException(typeof(Blog), blogId);
}
}
}

@ -7,5 +7,6 @@ namespace Volo.CmsKit.Blogs
public interface IBlogRepository : IBasicRepository<Blog, Guid>
{
public Task<Blog> GetByUrlSlugAsync(string urlSlug);
Task<bool> ExistsAsync(Guid blogId);
}
}

@ -1,4 +1,6 @@
using System;
using Microsoft.EntityFrameworkCore;
using System;
using System.Security.Cryptography.X509Certificates;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
@ -12,6 +14,11 @@ namespace Volo.CmsKit.Blogs
{
}
public async Task<bool> ExistsAsync(Guid blogId)
{
return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId);
}
public Task<Blog> GetByUrlSlugAsync(string urlSlug)
{
return GetAsync(x => x.UrlSlug == urlSlug);

@ -1,4 +1,5 @@
using System;
using MongoDB.Driver.Core.Operations;
using System;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB;
@ -12,6 +13,13 @@ namespace Volo.CmsKit.MongoDB.Blogs
{
}
public async Task<bool> ExistsAsync(Guid blogId)
{
return await AsyncExecuter.AnyAsync(
await GetQueryableAsync(),
x => x.Id == blogId);
}
public Task<Blog> GetByUrlSlugAsync(string urlSlug)
{
return GetAsync(x => x.UrlSlug == urlSlug);

@ -43,5 +43,23 @@ namespace Volo.CmsKit.Blogs
exception.ShouldNotBeNull();
exception.EntityType.ShouldBe(typeof(Blog));
}
[Fact]
public async Task ExistsAsync_ShouldReturnTrue_WithExistingId()
{
var result = await blogRepository.ExistsAsync(testData.Blog_Id);
result.ShouldBeTrue();
}
[Fact]
public async Task ExistsAsync_ShouldReturnFalse_WithExistingId()
{
var nonExistingId = Guid.NewGuid();
var result = await blogRepository.ExistsAsync(nonExistingId);
result.ShouldBeFalse();
}
}
}

Loading…
Cancel
Save