Browse Source

Merge pull request #7806 from abpframework/cms-kit-refactoring-and-code-fix

Cms Kit - Refactorings and code fixes
pull/7827/head
Ahmet Çotur 6 years ago
committed by GitHub
parent
commit
9133a96bce
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 16
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogPostAdminAppService.cs
  2. 2
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs
  3. 4
      modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs
  4. 3
      modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/MediaDescriptors/MediaDescriptorAdminController.cs
  5. 4
      modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/MediaDescriptors/MediaDescriptorAppService.cs
  6. 2
      modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Tags/TagAppService.cs
  7. 5
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Extensions/SlugExtensions.cs
  8. 32
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs
  9. 0
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentAlreadyExistException.cs
  10. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs
  11. 6
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/Tag.cs
  12. 51
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs
  13. 9
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs
  14. 13
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs
  15. 12
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs
  16. 5
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs
  17. 13
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs
  18. 51
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs
  19. 5
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs
  20. 26
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs
  21. 34
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs
  22. 22
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs
  23. 10
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs
  24. 10
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs
  25. 2
      modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs

16
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogPostAdminAppService.cs

@ -27,11 +27,11 @@ namespace Volo.CmsKit.Admin.Blogs
UpdateBlogPostDto> UpdateBlogPostDto>
, IBlogPostAdminAppService , IBlogPostAdminAppService
{ {
protected readonly IBlogPostManager BlogPostManager; protected IBlogPostManager BlogPostManager { get; }
protected readonly IBlogPostRepository BlogPostRepository; protected IBlogPostRepository BlogPostRepository { get; }
protected readonly IBlogRepository BlogRepository; protected IBlogRepository BlogRepository { get; }
protected readonly IBlobContainer<BlogPostCoverImageContainer> BlobContainer; protected IBlobContainer<BlogPostCoverImageContainer> BlobContainer { get; }
protected readonly ICmsUserLookupService UserLookupService; protected ICmsUserLookupService UserLookupService { get; }
public BlogPostAdminAppService( public BlogPostAdminAppService(
IRepository<BlogPost, Guid> repository, IRepository<BlogPost, Guid> repository,
@ -60,7 +60,7 @@ namespace Volo.CmsKit.Admin.Blogs
var blogPost = await BlogPostRepository.GetBySlugAsync(blog.Id, blogPostSlug); var blogPost = await BlogPostRepository.GetBySlugAsync(blog.Id, blogPostSlug);
return MapToGetOutputDto(blogPost); return await MapToGetOutputDtoAsync(blogPost);
} }
[Authorize(CmsKitAdminPermissions.BlogPosts.Create)] [Authorize(CmsKitAdminPermissions.BlogPosts.Create)]
@ -77,7 +77,7 @@ namespace Volo.CmsKit.Admin.Blogs
input.Slug, input.Slug,
input.ShortDescription)); input.ShortDescription));
return MapToGetOutputDto(entity); return await MapToGetOutputDtoAsync(entity);
} }
[Authorize(CmsKitAdminPermissions.BlogPosts.Update)] [Authorize(CmsKitAdminPermissions.BlogPosts.Update)]
@ -96,7 +96,7 @@ namespace Volo.CmsKit.Admin.Blogs
await BlogPostManager.UpdateAsync(blogPost); await BlogPostManager.UpdateAsync(blogPost);
return MapToGetOutputDto(blogPost); return await MapToGetOutputDtoAsync(blogPost);
} }
public virtual async Task SetCoverImageAsync(Guid id, RemoteStreamContent streamContent) public virtual async Task SetCoverImageAsync(Guid id, RemoteStreamContent streamContent)

2
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs

@ -53,7 +53,7 @@ namespace Volo.CmsKit.Admin.Contents
await ContentManager.InsertAsync(entity); await ContentManager.InsertAsync(entity);
return MapToGetOutputDto(entity); return await MapToGetOutputDtoAsync(entity);
} }
public virtual async Task<ContentDto> GetAsync( public virtual async Task<ContentDto> GetAsync(

4
modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs

@ -50,7 +50,7 @@ namespace Volo.CmsKit.Admin.Tags
input.Name, input.Name,
CurrentTenant?.Id); CurrentTenant?.Id);
return MapToGetOutputDto(tag); return await MapToGetOutputDtoAsync(tag);
} }
[Authorize(CmsKitAdminPermissions.Tags.Update)] [Authorize(CmsKitAdminPermissions.Tags.Update)]
@ -60,7 +60,7 @@ namespace Volo.CmsKit.Admin.Tags
id, id,
input.Name); input.Name);
return MapToGetOutputDto(tag); return await MapToGetOutputDtoAsync(tag);
} }
protected override IQueryable<Tag> CreateFilteredQuery(TagGetListInput input) protected override IQueryable<Tag> CreateFilteredQuery(TagGetListInput input)
{ {

3
modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/MediaDescriptors/MediaDescriptorAdminController.cs

@ -1,4 +1,5 @@
using System; using System;
using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Http;
@ -57,7 +58,7 @@ namespace Volo.CmsKit.Admin.MediaDescriptors
var mediaDescriptorDto = await MediaDescriptorAdminAppService.CreateAsync(inputStream); var mediaDescriptorDto = await MediaDescriptorAdminAppService.CreateAsync(inputStream);
return StatusCode(201, mediaDescriptorDto); return StatusCode((int)HttpStatusCode.Created, mediaDescriptorDto);
} }
} }
} }

4
modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/MediaDescriptors/MediaDescriptorAppService.cs

@ -10,8 +10,8 @@ namespace Volo.CmsKit.MediaDescriptors
[RequiresGlobalFeature(typeof(MediaFeature))] [RequiresGlobalFeature(typeof(MediaFeature))]
public class MediaDescriptorAppService : CmsKitAppServiceBase, IMediaDescriptorAppService public class MediaDescriptorAppService : CmsKitAppServiceBase, IMediaDescriptorAppService
{ {
protected readonly IMediaDescriptorRepository MediaDescriptorRepository; protected IMediaDescriptorRepository MediaDescriptorRepository { get; }
protected readonly IBlobContainer<MediaContainer> MediaContainer; protected IBlobContainer<MediaContainer> MediaContainer { get; }
public MediaDescriptorAppService(IMediaDescriptorRepository mediaDescriptorRepository, IBlobContainer<MediaContainer> mediaContainer) public MediaDescriptorAppService(IMediaDescriptorRepository mediaDescriptorRepository, IBlobContainer<MediaContainer> mediaContainer)
{ {

2
modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Tags/TagAppService.cs

@ -9,7 +9,7 @@ namespace Volo.CmsKit.Tags
{ {
public class TagAppService : CmsKitAppServiceBase, ITagAppService public class TagAppService : CmsKitAppServiceBase, ITagAppService
{ {
protected readonly ITagRepository TagRepository; protected ITagRepository TagRepository { get; }
public TagAppService(ITagRepository tagRepository) public TagAppService(ITagRepository tagRepository)
{ {

5
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Extensions/SlugExtensions.cs

@ -5,11 +5,10 @@ namespace Volo.CmsKit.Blogs.Extensions
{ {
public static class SlugExtensions public static class SlugExtensions
{ {
static readonly SlugHelper SlugHelper = new ();
public static string NormalizeSlug(this string value) public static string NormalizeSlug(this string value)
{ {
var slugHelper = new SlugHelper(); return SlugHelper.GenerateSlug(value?.Unidecode());
return slugHelper.GenerateSlug(value?.Unidecode());
} }
} }
} }

32
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs

@ -8,41 +8,37 @@ namespace Volo.CmsKit.Contents
{ {
public class Content : FullAuditedAggregateRoot<Guid>, IMultiTenant public class Content : FullAuditedAggregateRoot<Guid>, IMultiTenant
{ {
[CanBeNull] [CanBeNull] public virtual Guid? TenantId { get; protected set; }
public virtual Guid? TenantId { get; protected set; }
[NotNull] public virtual string EntityType { get; protected set; }
[NotNull]
public virtual string EntityType { get; protected set; } [NotNull] public virtual string EntityId { get; protected set; }
[NotNull] [NotNull] public virtual string Value { get; protected set; }
public virtual string EntityId { get; protected set; }
[NotNull]
public virtual string Value { get; protected set; }
protected Content() protected Content()
{ {
} }
public Content(Guid id, [NotNull] string entityType, [NotNull] string entityId, [NotNull] string value, Guid? tenantId = null) : base(id) public Content(Guid id, [NotNull] string entityType, [NotNull] string entityId, [NotNull] string value,
Guid? tenantId = null) : base(id)
{ {
EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId), ContentConsts.MaxEntityIdLength); EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId), ContentConsts.MaxEntityIdLength);
EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength); EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength);
Value = Check.NotNullOrEmpty(value, nameof(value), ContentConsts.MaxValueLength); Value = Check.NotNullOrEmpty(value, nameof(value), ContentConsts.MaxValueLength);
TenantId = tenantId; TenantId = tenantId;
} }
public void SetValue([NotNull] string value) public virtual void SetValue([NotNull] string value)
{ {
Value = Check.NotNullOrEmpty(value, nameof(value), ContentConsts.MaxValueLength); Value = Check.NotNullOrEmpty(value, nameof(value), ContentConsts.MaxValueLength);
} }
public void SetEntity([NotNull] string entityType, [NotNull] string entityId) public virtual void SetEntity([NotNull] string entityType, [NotNull] string entityId)
{ {
EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength); EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength);
EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId), ContentConsts.MaxEntityIdLength); EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId), ContentConsts.MaxEntityIdLength);
} }
} }
} }

0
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/TagAlreadyExistException.cs → modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentAlreadyExistException.cs

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

@ -8,7 +8,7 @@ namespace Volo.CmsKit.Pages
{ {
public class Page : FullAuditedAggregateRoot<Guid>, IMultiTenant public class Page : FullAuditedAggregateRoot<Guid>, IMultiTenant
{ {
[CanBeNull] public virtual Guid? TenantId { get; set; } [CanBeNull] public virtual Guid? TenantId { get; protected set; }
[NotNull] public virtual string Title { get; protected set; } [NotNull] public virtual string Title { get; protected set; }

6
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/Tag.cs

@ -8,7 +8,7 @@ namespace Volo.CmsKit.Tags
{ {
public class Tag : FullAuditedAggregateRoot<Guid>, IMultiTenant public class Tag : FullAuditedAggregateRoot<Guid>, IMultiTenant
{ {
public virtual Guid? TenantId { get; set; } public virtual Guid? TenantId { get; protected set; }
[NotNull] [NotNull]
public virtual string EntityType { get; protected set; } public virtual string EntityType { get; protected set; }
@ -31,9 +31,9 @@ namespace Volo.CmsKit.Tags
TenantId = tenantId; TenantId = tenantId;
} }
public virtual void SetName(string name) public virtual void SetName([NotNull] string name)
{ {
Name = Check.NotNullOrWhiteSpace(name, nameof(name), TagConsts.MaxNameLength); Name = Check.NotNullOrEmpty(name, nameof(name), TagConsts.MaxNameLength);
} }
public virtual void SetEntityType(string entityType) public virtual void SetEntityType(string entityType)

51
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs

@ -10,6 +10,8 @@ using Volo.Abp.EntityFrameworkCore;
using Volo.CmsKit.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore;
using System.Linq; using System.Linq;
using System.Data.Common; using System.Data.Common;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities;
namespace Volo.CmsKit.Blogs namespace Volo.CmsKit.Blogs
@ -20,30 +22,30 @@ namespace Volo.CmsKit.Blogs
{ {
} }
public async Task<BlogPost> GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) public async Task<BlogPost> GetBySlugAsync(Guid blogId, [NotNull] string slug,
CancellationToken cancellationToken = default)
{ {
var dbSet = await GetDbSetAsync(); Check.NotNullOrEmpty(slug, nameof(slug));
return await dbSet return await (await WithDetailsAsync())
.Include(i=> i.Creator) .Where(x =>
.Where(x => x.BlogId == blogId && x.Slug.ToLower() == slug)
x.BlogId == blogId && x.Slug.ToLower() == slug) .FirstOrDefaultAsync(cancellationToken: GetCancellationToken(cancellationToken))
.FirstOrDefaultAsync(cancellationToken: cancellationToken) ?? throw new EntityNotFoundException(typeof(BlogPost));
?? throw new EntityNotFoundException(typeof(BlogPost));
} }
public async Task<int> GetCountAsync(Guid blogId, CancellationToken cancellationToken = default) public async Task<int> GetCountAsync(Guid blogId, CancellationToken cancellationToken = default)
{ {
return await (await GetQueryableAsync()).CountAsync( return await (await GetQueryableAsync()).CountAsync(
x => x.BlogId == blogId, x => x.BlogId == blogId,
cancellationToken); GetCancellationToken(cancellationToken));
} }
public async Task<List<BlogPost>> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) public async Task<List<BlogPost>> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount,
string sorting, bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
var queryable = (await GetQueryableAsync()) var queryable = (await WithDetailsAsync())
.Include(i => i.Creator) .Where(x => x.BlogId == blogId);
.Where(x => x.BlogId == blogId);
if (!sorting.IsNullOrWhiteSpace()) if (!sorting.IsNullOrWhiteSpace())
{ {
@ -51,16 +53,23 @@ namespace Volo.CmsKit.Blogs
} }
return await queryable return await queryable
.Skip(skipCount) .Skip(skipCount)
.Take(maxResultCount) .Take(maxResultCount)
.ToListAsync(cancellationToken); .ToListAsync(GetCancellationToken());
} }
public async Task<bool> SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) public async Task<bool> SlugExistsAsync(Guid blogId, [NotNull] string slug,
CancellationToken cancellationToken = default)
{ {
var dbSet = await GetDbSetAsync(); Check.NotNullOrEmpty(slug, nameof(slug));
return await dbSet.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, cancellationToken); return await (await WithDetailsAsync()).AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug,
GetCancellationToken(cancellationToken));
}
public override async Task<IQueryable<BlogPost>> WithDetailsAsync()
{
return (await GetDbSetAsync()).Include(i => i.Creator);
} }
} }
} }

9
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs

@ -3,6 +3,8 @@ using System;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.CmsKit.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore;
@ -17,12 +19,13 @@ namespace Volo.CmsKit.Blogs
public virtual async Task<bool> ExistsAsync(Guid blogId, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync(Guid blogId, CancellationToken cancellationToken = default)
{ {
return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId, cancellationToken); return await (await GetQueryableAsync()).AnyAsync(x => x.Id == blogId, GetCancellationToken(cancellationToken));
} }
public virtual Task<Blog> GetBySlugAsync(string slug, CancellationToken cancellationToken = default) public virtual Task<Blog> GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default)
{ {
return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken); Check.NotNullOrEmpty(slug, nameof(slug));
return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
} }
} }
} }

13
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs

@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore;
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.CmsKit.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore;
@ -21,6 +22,9 @@ namespace Volo.CmsKit.Contents
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId));
return GetAsync(x => return GetAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.EntityId == entityId && x.EntityId == entityId &&
@ -35,6 +39,9 @@ namespace Volo.CmsKit.Contents
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId));
return FindAsync(x => return FindAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.EntityId == entityId && x.EntityId == entityId &&
@ -49,6 +56,9 @@ namespace Volo.CmsKit.Contents
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId));
return DeleteAsync(x => return DeleteAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.EntityId == entityId && x.EntityId == entityId &&
@ -62,6 +72,9 @@ namespace Volo.CmsKit.Contents
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId));
var dbSet = await GetDbSetAsync(); var dbSet = await GetDbSetAsync();
return await dbSet.AnyAsync(x => return await dbSet.AnyAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&

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

@ -4,7 +4,9 @@ using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.CmsKit.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore;
@ -43,18 +45,22 @@ namespace Volo.CmsKit.Pages
.ToListAsync(GetCancellationToken(cancellationToken)); .ToListAsync(GetCancellationToken(cancellationToken));
} }
public virtual Task<Page> GetBySlugAsync(string slug, CancellationToken cancellationToken = default) public virtual Task<Page> GetBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(slug, nameof(slug));
return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual Task<Page> FindBySlugAsync(string slug, CancellationToken cancellationToken = default) public virtual Task<Page> FindBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(slug, nameof(slug));
return FindAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); return FindAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual async Task<bool> ExistsAsync(string slug, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync([NotNull] string slug,
CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(slug, nameof(slug));
return await (await GetDbSetAsync()).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken)); return await (await GetDbSetAsync()).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken));
} }
} }

5
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs

@ -3,6 +3,7 @@ using System;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.CmsKit.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore;
@ -30,11 +31,13 @@ namespace Volo.CmsKit.Tags
[CanBeNull] Guid? tenantId, [CanBeNull] Guid? tenantId,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityId, nameof(entityId));
return base.FindAsync(x => return base.FindAsync(x =>
x.TagId == tagId && x.TagId == tagId &&
x.EntityId == entityId && x.EntityId == entityId &&
x.TenantId == tenantId, x.TenantId == tenantId,
cancellationToken: cancellationToken); cancellationToken: GetCancellationToken(cancellationToken));
} }
} }
} }

13
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs

@ -5,6 +5,7 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore;
using Volo.CmsKit.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore;
@ -23,6 +24,9 @@ namespace Volo.CmsKit.Tags
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(name, nameof(name));
return await (await GetDbSetAsync()).AnyAsync(x => return await (await GetDbSetAsync()).AnyAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.Name == name && x.Name == name &&
@ -36,6 +40,9 @@ namespace Volo.CmsKit.Tags
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(name, nameof(name));
return GetAsync(x => return GetAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.Name == name && x.Name == name &&
@ -49,6 +56,9 @@ namespace Volo.CmsKit.Tags
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(name, nameof(name));
return FindAsync(x => return FindAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.Name == name && x.Name == name &&
@ -62,6 +72,9 @@ namespace Volo.CmsKit.Tags
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId));
var entityTagIds = await (await GetDbContextAsync()).Set<EntityTag>() var entityTagIds = await (await GetDbContextAsync()).Set<EntityTag>()
.Where(q => q.EntityId == entityId && q.TenantId == tenantId) .Where(q => q.EntityId == entityId && q.TenantId == tenantId)
.Select(q => q.TagId) .Select(q => q.TagId)

51
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs

@ -7,6 +7,8 @@ using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
using Volo.CmsKit.Blogs; using Volo.CmsKit.Blogs;
@ -16,34 +18,40 @@ namespace Volo.CmsKit.MongoDB.Blogs
{ {
public class MongoBlogPostRepository : MongoDbRepository<CmsKitMongoDbContext, BlogPost, Guid>, IBlogPostRepository public class MongoBlogPostRepository : MongoDbRepository<CmsKitMongoDbContext, BlogPost, Guid>, IBlogPostRepository
{ {
public MongoBlogPostRepository(IMongoDbContextProvider<CmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) public MongoBlogPostRepository(IMongoDbContextProvider<CmsKitMongoDbContext> dbContextProvider) : base(
dbContextProvider)
{ {
} }
public Task<BlogPost> GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) public Task<BlogPost> GetBySlugAsync(Guid blogId, [NotNull] string slug,
CancellationToken cancellationToken = default)
{ {
return GetAsync(x => Check.NotNullOrEmpty(slug, nameof(slug));
x.BlogId == blogId &&
x.Slug.ToLower() == slug, return GetAsync(x =>
includeDetails: true, x.BlogId == blogId &&
cancellationToken: cancellationToken); x.Slug.ToLower() == slug,
includeDetails: true,
cancellationToken: GetCancellationToken(cancellationToken));
} }
public async Task<int> GetCountAsync(Guid blogId, CancellationToken cancellationToken = default) public async Task<int> GetCountAsync(Guid blogId, CancellationToken cancellationToken = default)
{ {
return await AsyncExecuter.CountAsync( return await AsyncExecuter.CountAsync(
await WithDetailsAsync(), await WithDetailsAsync(),
x => x.BlogId == blogId, x => x.BlogId == blogId,
cancellationToken); GetCancellationToken(cancellationToken));
} }
public async Task<List<BlogPost>> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) public async Task<List<BlogPost>> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount,
string sorting, bool includeDetails = false, CancellationToken cancellationToken = default)
{ {
var dbContext = await GetDbContextAsync(cancellationToken); var token = GetCancellationToken(cancellationToken);
var dbContext = await GetDbContextAsync(token);
var blogPostQueryable = await WithDetailsAsync(); var blogPostQueryable = await WithDetailsAsync();
var queryable = blogPostQueryable var queryable = blogPostQueryable
.Where(x => x.BlogId == blogId); .Where(x => x.BlogId == blogId);
if (!sorting.IsNullOrWhiteSpace()) if (!sorting.IsNullOrWhiteSpace())
{ {
@ -51,17 +59,20 @@ namespace Volo.CmsKit.MongoDB.Blogs
} }
queryable = queryable queryable = queryable
.Skip(skipCount) .Skip(skipCount)
.Take(maxResultCount); .Take(maxResultCount);
return await AsyncExecuter.ToListAsync(queryable, cancellationToken); return await AsyncExecuter.ToListAsync(queryable, token);
} }
public async Task<bool> SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) public async Task<bool> SlugExistsAsync(Guid blogId, [NotNull] string slug,
CancellationToken cancellationToken = default)
{ {
var queryable = await GetMongoQueryableAsync(); Check.NotNullOrEmpty(slug, nameof(slug));
return await queryable.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, cancellationToken); var token = GetCancellationToken(cancellationToken);
var queryable = await GetMongoQueryableAsync(token);
return await queryable.AnyAsync(x => x.BlogId == blogId && x.Slug.ToLower() == slug, token);
} }
} }
} }

5
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs

@ -2,6 +2,8 @@
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using JetBrains.Annotations;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
using Volo.CmsKit.Blogs; using Volo.CmsKit.Blogs;
@ -22,8 +24,9 @@ namespace Volo.CmsKit.MongoDB.Blogs
cancellationToken); cancellationToken);
} }
public virtual Task<Blog> GetBySlugAsync(string slug, CancellationToken cancellationToken = default) public virtual Task<Blog> GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(slug, nameof(slug));
return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken); return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken);
} }
} }

26
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs

@ -3,6 +3,7 @@ using MongoDB.Driver.Linq;
using System; using System;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
using Volo.CmsKit.Contents; using Volo.CmsKit.Contents;
@ -11,7 +12,8 @@ namespace Volo.CmsKit.MongoDB.Contents
{ {
public class MongoContentRepository : MongoDbRepository<ICmsKitMongoDbContext, Content, Guid>, IContentRepository public class MongoContentRepository : MongoDbRepository<ICmsKitMongoDbContext, Content, Guid>, IContentRepository
{ {
public MongoContentRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) public MongoContentRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(
dbContextProvider)
{ {
} }
@ -21,6 +23,9 @@ namespace Volo.CmsKit.MongoDB.Contents
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId));
return GetAsync(x => return GetAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.EntityId == entityId && x.EntityId == entityId &&
@ -28,23 +33,30 @@ namespace Volo.CmsKit.MongoDB.Contents
cancellationToken: GetCancellationToken(cancellationToken) cancellationToken: GetCancellationToken(cancellationToken)
); );
} }
public virtual Task<Content> FindAsync( public virtual Task<Content> FindAsync(
string entityType, string entityType,
string entityId, string entityId,
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId));
return FindAsync(x => return FindAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.EntityId == entityId && x.EntityId == entityId &&
x.TenantId == tenantId, x.TenantId == tenantId,
cancellationToken: GetCancellationToken(cancellationToken) cancellationToken: GetCancellationToken(cancellationToken)
); );
} }
public virtual Task DeleteAsync(string entityType, string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) public virtual Task DeleteAsync(string entityType, string entityId, Guid? tenantId = null,
CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId));
return DeleteAsync(x => return DeleteAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.EntityId == entityId && x.EntityId == entityId &&
@ -52,8 +64,12 @@ namespace Volo.CmsKit.MongoDB.Contents
cancellationToken: GetCancellationToken(cancellationToken)); cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual async Task<bool> ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync([NotNull] string entityType, [NotNull] string entityId,
Guid? tenantId = null, CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId));
return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.EntityId == entityId && x.EntityId == entityId &&

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

@ -1,10 +1,12 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Dynamic.Core; using System.Linq.Dynamic.Core;
using JetBrains.Annotations;
using MongoDB.Driver;
using Volo.Abp;
using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using MongoDB.Driver;
using MongoDB.Driver.Linq; using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
@ -14,14 +16,16 @@ namespace Volo.CmsKit.MongoDB.Pages
{ {
public class MongoPageRepository : MongoDbRepository<ICmsKitMongoDbContext, Page, Guid>, IPageRepository public class MongoPageRepository : MongoDbRepository<ICmsKitMongoDbContext, Page, Guid>, IPageRepository
{ {
public MongoPageRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) public MongoPageRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(
dbContextProvider)
{ {
} }
public virtual async Task<int> GetCountAsync(string filter = null, CancellationToken cancellationToken = default) public virtual async Task<int> GetCountAsync(string filter = null,
CancellationToken cancellationToken = default)
{ {
var cancellation = GetCancellationToken(cancellationToken); var cancellation = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellation)) return await (await GetMongoQueryableAsync(cancellation))
.WhereIf<Page, IMongoQueryable<Page>>( .WhereIf<Page, IMongoQueryable<Page>>(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
@ -33,12 +37,12 @@ namespace Volo.CmsKit.MongoDB.Pages
public virtual async Task<List<Page>> GetListAsync( public virtual async Task<List<Page>> GetListAsync(
string filter = null, string filter = null,
int maxResultCount = int.MaxValue, int maxResultCount = int.MaxValue,
int skipCount = 0, int skipCount = 0,
string sorting = null, string sorting = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
var cancellation = GetCancellationToken(cancellationToken); var cancellation = GetCancellationToken(cancellationToken);
return await (await GetMongoQueryableAsync(cancellation)) return await (await GetMongoQueryableAsync(cancellation))
.WhereIf<Page, IMongoQueryable<Page>>( .WhereIf<Page, IMongoQueryable<Page>>(
!filter.IsNullOrWhiteSpace(), !filter.IsNullOrWhiteSpace(),
@ -51,19 +55,23 @@ namespace Volo.CmsKit.MongoDB.Pages
.ToListAsync(cancellation); .ToListAsync(cancellation);
} }
public virtual Task<Page> GetBySlugAsync(string slug, CancellationToken cancellationToken = default) public virtual Task<Page> GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(slug, nameof(slug));
return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual Task<Page> FindBySlugAsync(string slug, CancellationToken cancellationToken = default) public virtual Task<Page> FindBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(slug, nameof(slug));
return FindAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); return FindAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken));
} }
public virtual async Task<bool> ExistsAsync(string slug, CancellationToken cancellationToken = default) public virtual async Task<bool> ExistsAsync([NotNull]string slug, CancellationToken cancellationToken = default)
{ {
return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken)); Check.NotNullOrEmpty(slug, nameof(slug));
return await (await GetMongoQueryableAsync(cancellationToken)).AnyAsync(x => x.Slug == slug,
GetCancellationToken(cancellationToken));
} }
} }
} }

22
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs

@ -4,23 +4,26 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
using Volo.CmsKit.Tags; using Volo.CmsKit.Tags;
namespace Volo.CmsKit.MongoDB.Tags namespace Volo.CmsKit.MongoDB.Tags
{ {
public class MongoEntityTagRepository: MongoDbRepository<ICmsKitMongoDbContext, EntityTag>, IEntityTagRepository public class MongoEntityTagRepository : MongoDbRepository<ICmsKitMongoDbContext, EntityTag>, IEntityTagRepository
{ {
public MongoEntityTagRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) public MongoEntityTagRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(
dbContextProvider)
{ {
} }
public async Task DeleteManyAsync(Guid[] tagIds, CancellationToken cancellationToken = default) public async Task DeleteManyAsync(Guid[] tagIds, CancellationToken cancellationToken = default)
{ {
var collection = await GetCollectionAsync(); var token = GetCancellationToken(cancellationToken);
await collection.DeleteManyAsync(Builders<EntityTag>.Filter.In(x => x.TagId, tagIds)); var collection = await GetCollectionAsync(token);
await collection.DeleteManyAsync(Builders<EntityTag>.Filter.In(x => x.TagId, tagIds), token);
} }
public Task<EntityTag> FindAsync( public Task<EntityTag> FindAsync(
@ -29,11 +32,12 @@ namespace Volo.CmsKit.MongoDB.Tags
[CanBeNull] Guid? tenantId, [CanBeNull] Guid? tenantId,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityId, nameof(entityId));
return base.FindAsync(x => return base.FindAsync(x =>
x.TagId == tagId && x.TagId == tagId &&
x.EntityId == entityId && x.EntityId == entityId &&
x.TenantId == tenantId, x.TenantId == tenantId,
cancellationToken: cancellationToken); cancellationToken: GetCancellationToken(cancellationToken));
} }
} }
} }

10
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs

@ -5,6 +5,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using Volo.Abp;
using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB; using Volo.Abp.MongoDB;
using Volo.CmsKit.Tags; using Volo.CmsKit.Tags;
@ -24,6 +25,9 @@ namespace Volo.CmsKit.MongoDB.Tags
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(name, nameof(name));
return await (await GetMongoQueryableAsync(cancellationToken)) return await (await GetMongoQueryableAsync(cancellationToken))
.AnyAsync(x => .AnyAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
@ -51,6 +55,9 @@ namespace Volo.CmsKit.MongoDB.Tags
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(name, nameof(name));
return FindAsync(x => return FindAsync(x =>
x.EntityType == entityType && x.EntityType == entityType &&
x.Name == name && x.Name == name &&
@ -64,6 +71,9 @@ namespace Volo.CmsKit.MongoDB.Tags
Guid? tenantId = null, Guid? tenantId = null,
CancellationToken cancellationToken = default) CancellationToken cancellationToken = default)
{ {
Check.NotNullOrEmpty(entityType, nameof(entityType));
Check.NotNullOrEmpty(entityId, nameof(entityId));
var entityTagIds = await (await GetDbContextAsync(cancellationToken)).EntityTags.AsQueryable() var entityTagIds = await (await GetDbContextAsync(cancellationToken)).EntityTags.AsQueryable()
.Where(q => q.EntityId == entityId && q.TenantId == tenantId) .Where(q => q.EntityId == entityId && q.TenantId == tenantId)
.Select(q => q.TagId) .Select(q => q.TagId)

10
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs

@ -1,27 +1,29 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc; using Microsoft.AspNetCore.Mvc;
using Volo.Abp; using Volo.Abp;
using Volo.Abp.GlobalFeatures;
using Volo.CmsKit.Contents; using Volo.CmsKit.Contents;
using Volo.CmsKit.GlobalFeatures;
namespace Volo.CmsKit.Public.Contents namespace Volo.CmsKit.Public.Contents
{ {
[RequiresGlobalFeature(typeof(ContentsFeature))]
[RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)]
[Area("cms-kit")] [Area("cms-kit")]
[Route("api/cms-kit-public/contents")] [Route("api/cms-kit-public/contents")]
public class ContentController : CmsKitControllerBase, IContentPublicAppService public class ContentController : CmsKitControllerBase, IContentPublicAppService
{ {
protected readonly IContentPublicAppService _contentAppService; protected IContentPublicAppService ContentAppService { get; }
public ContentController(IContentPublicAppService contentAppService) public ContentController(IContentPublicAppService contentAppService)
{ {
_contentAppService = contentAppService; ContentAppService = contentAppService;
} }
[HttpGet] [HttpGet]
public virtual Task<ContentDto> GetAsync(GetContentInput input) public virtual Task<ContentDto> GetAsync(GetContentInput input)
{ {
return _contentAppService.GetAsync(input); return ContentAppService.GetAsync(input);
} }
} }
} }

2
modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs

@ -14,7 +14,7 @@ namespace Volo.CmsKit.Public.Tags
[Route("api/cms-kit-public/tags")] [Route("api/cms-kit-public/tags")]
public class TagPublicController : CmsKitPublicControllerBase, ITagAppService public class TagPublicController : CmsKitPublicControllerBase, ITagAppService
{ {
protected readonly ITagAppService TagAppService; protected ITagAppService TagAppService { get; }
public TagPublicController(ITagAppService tagAppService) public TagPublicController(ITagAppService tagAppService)
{ {

Loading…
Cancel
Save