diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogPostAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogPostAdminAppService.cs index d2c1114dfb..fc57121040 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogPostAdminAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Blogs/BlogPostAdminAppService.cs @@ -27,11 +27,11 @@ namespace Volo.CmsKit.Admin.Blogs UpdateBlogPostDto> , IBlogPostAdminAppService { - protected readonly IBlogPostManager BlogPostManager; - protected readonly IBlogPostRepository BlogPostRepository; - protected readonly IBlogRepository BlogRepository; - protected readonly IBlobContainer BlobContainer; - protected readonly ICmsUserLookupService UserLookupService; + protected IBlogPostManager BlogPostManager { get; } + protected IBlogPostRepository BlogPostRepository { get; } + protected IBlogRepository BlogRepository { get; } + protected IBlobContainer BlobContainer { get; } + protected ICmsUserLookupService UserLookupService { get; } public BlogPostAdminAppService( IRepository repository, @@ -60,7 +60,7 @@ namespace Volo.CmsKit.Admin.Blogs var blogPost = await BlogPostRepository.GetBySlugAsync(blog.Id, blogPostSlug); - return MapToGetOutputDto(blogPost); + return await MapToGetOutputDtoAsync(blogPost); } [Authorize(CmsKitAdminPermissions.BlogPosts.Create)] @@ -77,7 +77,7 @@ namespace Volo.CmsKit.Admin.Blogs input.Slug, input.ShortDescription)); - return MapToGetOutputDto(entity); + return await MapToGetOutputDtoAsync(entity); } [Authorize(CmsKitAdminPermissions.BlogPosts.Update)] @@ -96,7 +96,7 @@ namespace Volo.CmsKit.Admin.Blogs await BlogPostManager.UpdateAsync(blogPost); - return MapToGetOutputDto(blogPost); + return await MapToGetOutputDtoAsync(blogPost); } public virtual async Task SetCoverImageAsync(Guid id, RemoteStreamContent streamContent) diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs index 020b4fd29e..1aa0bffcfa 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Contents/ContentAdminAppService.cs +++ b/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); - return MapToGetOutputDto(entity); + return await MapToGetOutputDtoAsync(entity); } public virtual async Task GetAsync( diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs index fd276cb31a..15dde35076 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.Application/Volo/CmsKit/Admin/Tags/TagAdminAppService.cs +++ b/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, CurrentTenant?.Id); - return MapToGetOutputDto(tag); + return await MapToGetOutputDtoAsync(tag); } [Authorize(CmsKitAdminPermissions.Tags.Update)] @@ -60,7 +60,7 @@ namespace Volo.CmsKit.Admin.Tags id, input.Name); - return MapToGetOutputDto(tag); + return await MapToGetOutputDtoAsync(tag); } protected override IQueryable CreateFilteredQuery(TagGetListInput input) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/MediaDescriptors/MediaDescriptorAdminController.cs b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/MediaDescriptors/MediaDescriptorAdminController.cs index a3b438e341..4267f635b0 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/MediaDescriptors/MediaDescriptorAdminController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Admin.HttpApi/Volo/CmsKit/Admin/MediaDescriptors/MediaDescriptorAdminController.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Threading.Tasks; using Microsoft.AspNetCore.Authorization; using Microsoft.AspNetCore.Http; @@ -57,7 +58,7 @@ namespace Volo.CmsKit.Admin.MediaDescriptors var mediaDescriptorDto = await MediaDescriptorAdminAppService.CreateAsync(inputStream); - return StatusCode(201, mediaDescriptorDto); + return StatusCode((int)HttpStatusCode.Created, mediaDescriptorDto); } } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/MediaDescriptors/MediaDescriptorAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/MediaDescriptors/MediaDescriptorAppService.cs index 81879c5da9..0068390312 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/MediaDescriptors/MediaDescriptorAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/MediaDescriptors/MediaDescriptorAppService.cs @@ -10,8 +10,8 @@ namespace Volo.CmsKit.MediaDescriptors [RequiresGlobalFeature(typeof(MediaFeature))] public class MediaDescriptorAppService : CmsKitAppServiceBase, IMediaDescriptorAppService { - protected readonly IMediaDescriptorRepository MediaDescriptorRepository; - protected readonly IBlobContainer MediaContainer; + protected IMediaDescriptorRepository MediaDescriptorRepository { get; } + protected IBlobContainer MediaContainer { get; } public MediaDescriptorAppService(IMediaDescriptorRepository mediaDescriptorRepository, IBlobContainer mediaContainer) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Tags/TagAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Tags/TagAppService.cs index caa6dc4181..61dfb15571 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Common.Application/Volo/CmsKit/Tags/TagAppService.cs +++ b/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 { - protected readonly ITagRepository TagRepository; + protected ITagRepository TagRepository { get; } public TagAppService(ITagRepository tagRepository) { diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Extensions/SlugExtensions.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Extensions/SlugExtensions.cs index 9b3908d8cb..a625d4687f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/Extensions/SlugExtensions.cs +++ b/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 { + static readonly SlugHelper SlugHelper = new (); public static string NormalizeSlug(this string value) { - var slugHelper = new SlugHelper(); - - return slugHelper.GenerateSlug(value?.Unidecode()); + return SlugHelper.GenerateSlug(value?.Unidecode()); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs index 434ae4847b..392abfbc6f 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/Content.cs @@ -8,41 +8,37 @@ namespace Volo.CmsKit.Contents { public class Content : FullAuditedAggregateRoot, IMultiTenant { - [CanBeNull] - public virtual Guid? TenantId { get; protected set; } - - [NotNull] - public virtual string EntityType { get; protected set; } - - [NotNull] - public virtual string EntityId { get; protected set; } - - [NotNull] - public virtual string Value { get; protected set; } + [CanBeNull] public virtual Guid? TenantId { get; protected set; } + + [NotNull] public virtual string EntityType { get; protected set; } + + [NotNull] public virtual string EntityId { get; protected set; } + + [NotNull] public virtual string Value { get; protected set; } 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); EntityType = Check.NotNullOrEmpty(entityType, nameof(entityType), ContentConsts.MaxEntityTypeLength); Value = Check.NotNullOrEmpty(value, nameof(value), ContentConsts.MaxValueLength); - + TenantId = tenantId; } - public void SetValue([NotNull] string value) + public virtual void SetValue([NotNull] string value) { 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); EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId), ContentConsts.MaxEntityIdLength); } } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/TagAlreadyExistException.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentAlreadyExistException.cs similarity index 100% rename from modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/TagAlreadyExistException.cs rename to modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Contents/ContentAlreadyExistException.cs diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs index f56dcd10bc..cae13a5254 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Pages/Page.cs @@ -8,7 +8,7 @@ namespace Volo.CmsKit.Pages { public class Page : FullAuditedAggregateRoot, IMultiTenant { - [CanBeNull] public virtual Guid? TenantId { get; set; } + [CanBeNull] public virtual Guid? TenantId { get; protected set; } [NotNull] public virtual string Title { get; protected set; } diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/Tag.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/Tag.cs index 0c6ad99b2a..4b9aeebde1 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/Tag.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Tags/Tag.cs @@ -8,7 +8,7 @@ namespace Volo.CmsKit.Tags { public class Tag : FullAuditedAggregateRoot, IMultiTenant { - public virtual Guid? TenantId { get; set; } + public virtual Guid? TenantId { get; protected set; } [NotNull] public virtual string EntityType { get; protected set; } @@ -31,9 +31,9 @@ namespace Volo.CmsKit.Tags 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) diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs index 5a9c5d526a..b914b4ad01 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogPostRepository.cs +++ b/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 System.Linq; using System.Data.Common; +using JetBrains.Annotations; +using Volo.Abp; using Volo.Abp.Domain.Entities; namespace Volo.CmsKit.Blogs @@ -20,30 +22,30 @@ namespace Volo.CmsKit.Blogs { } - public async Task GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) + public async Task GetBySlugAsync(Guid blogId, [NotNull] string slug, + CancellationToken cancellationToken = default) { - var dbSet = await GetDbSetAsync(); + Check.NotNullOrEmpty(slug, nameof(slug)); - return await dbSet - .Include(i=> i.Creator) - .Where(x => - x.BlogId == blogId && x.Slug.ToLower() == slug) - .FirstOrDefaultAsync(cancellationToken: cancellationToken) - ?? throw new EntityNotFoundException(typeof(BlogPost)); + return await (await WithDetailsAsync()) + .Where(x => + x.BlogId == blogId && x.Slug.ToLower() == slug) + .FirstOrDefaultAsync(cancellationToken: GetCancellationToken(cancellationToken)) + ?? throw new EntityNotFoundException(typeof(BlogPost)); } public async Task GetCountAsync(Guid blogId, CancellationToken cancellationToken = default) { return await (await GetQueryableAsync()).CountAsync( - x => x.BlogId == blogId, - cancellationToken); + x => x.BlogId == blogId, + GetCancellationToken(cancellationToken)); } - public async Task> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) + public async Task> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, + string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) { - var queryable = (await GetQueryableAsync()) - .Include(i => i.Creator) - .Where(x => x.BlogId == blogId); + var queryable = (await WithDetailsAsync()) + .Where(x => x.BlogId == blogId); if (!sorting.IsNullOrWhiteSpace()) { @@ -51,16 +53,23 @@ namespace Volo.CmsKit.Blogs } return await queryable - .Skip(skipCount) - .Take(maxResultCount) - .ToListAsync(cancellationToken); + .Skip(skipCount) + .Take(maxResultCount) + .ToListAsync(GetCancellationToken()); } - public async Task SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) + public async Task 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> WithDetailsAsync() + { + return (await GetDbSetAsync()).Include(i => i.Creator); } } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs index f04889299c..c39dee2685 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Blogs/EfCoreBlogRepository.cs +++ b/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.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -17,12 +19,13 @@ namespace Volo.CmsKit.Blogs public virtual async Task 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 GetBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task 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)); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs index e8b88161ca..9a99bc5eca 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Contents/EfCoreContentRepository.cs @@ -3,6 +3,7 @@ using Microsoft.EntityFrameworkCore; using System; using System.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -21,6 +22,9 @@ namespace Volo.CmsKit.Contents Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return GetAsync(x => x.EntityType == entityType && x.EntityId == entityId && @@ -35,6 +39,9 @@ namespace Volo.CmsKit.Contents Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return FindAsync(x => x.EntityType == entityType && x.EntityId == entityId && @@ -49,6 +56,9 @@ namespace Volo.CmsKit.Contents Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return DeleteAsync(x => x.EntityType == entityType && x.EntityId == entityId && @@ -62,6 +72,9 @@ namespace Volo.CmsKit.Contents Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + var dbSet = await GetDbSetAsync(); return await dbSet.AnyAsync(x => x.EntityType == entityType && diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs index 3c213d98b3..d1d5578c02 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Pages/EfCorePageRepository.cs +++ b/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.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; using Microsoft.EntityFrameworkCore; +using Volo.Abp; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -43,18 +45,22 @@ namespace Volo.CmsKit.Pages .ToListAsync(GetCancellationToken(cancellationToken)); } - public virtual Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task GetBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); } - public virtual Task FindBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task FindBySlugAsync([NotNull] string slug, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return FindAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); } - public virtual async Task ExistsAsync(string slug, CancellationToken cancellationToken = default) + public virtual async Task ExistsAsync([NotNull] string slug, + CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return await (await GetDbSetAsync()).AnyAsync(x => x.Slug == slug, GetCancellationToken(cancellationToken)); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs index 5e1bbcebea..ae5d081b6a 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreEntityTagRepository.cs @@ -3,6 +3,7 @@ using System; using System.Linq; using System.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -30,11 +31,13 @@ namespace Volo.CmsKit.Tags [CanBeNull] Guid? tenantId, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return base.FindAsync(x => x.TagId == tagId && x.EntityId == entityId && x.TenantId == tenantId, - cancellationToken: cancellationToken); + cancellationToken: GetCancellationToken(cancellationToken)); } } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs index 77c4854b8d..7325141c40 100644 --- a/modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Tags/EfCoreTagRepository.cs +++ b/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.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.EntityFrameworkCore; using Volo.Abp.EntityFrameworkCore; using Volo.CmsKit.EntityFrameworkCore; @@ -23,6 +24,9 @@ namespace Volo.CmsKit.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(name, nameof(name)); + return await (await GetDbSetAsync()).AnyAsync(x => x.EntityType == entityType && x.Name == name && @@ -36,6 +40,9 @@ namespace Volo.CmsKit.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(name, nameof(name)); + return GetAsync(x => x.EntityType == entityType && x.Name == name && @@ -49,6 +56,9 @@ namespace Volo.CmsKit.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(name, nameof(name)); + return FindAsync(x => x.EntityType == entityType && x.Name == name && @@ -62,6 +72,9 @@ namespace Volo.CmsKit.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + var entityTagIds = await (await GetDbContextAsync()).Set() .Where(q => q.EntityId == entityId && q.TenantId == tenantId) .Select(q => q.TagId) diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs index 85dc1b86e0..6c75e7fec3 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogPostRepository.cs +++ b/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.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Blogs; @@ -16,34 +18,40 @@ namespace Volo.CmsKit.MongoDB.Blogs { public class MongoBlogPostRepository : MongoDbRepository, IBlogPostRepository { - public MongoBlogPostRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) + public MongoBlogPostRepository(IMongoDbContextProvider dbContextProvider) : base( + dbContextProvider) { } - public Task GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) + public Task GetBySlugAsync(Guid blogId, [NotNull] string slug, + CancellationToken cancellationToken = default) { - return GetAsync(x => - x.BlogId == blogId && - x.Slug.ToLower() == slug, - includeDetails: true, - cancellationToken: cancellationToken); + Check.NotNullOrEmpty(slug, nameof(slug)); + + return GetAsync(x => + x.BlogId == blogId && + x.Slug.ToLower() == slug, + includeDetails: true, + cancellationToken: GetCancellationToken(cancellationToken)); } public async Task GetCountAsync(Guid blogId, CancellationToken cancellationToken = default) { return await AsyncExecuter.CountAsync( - await WithDetailsAsync(), - x => x.BlogId == blogId, - cancellationToken); + await WithDetailsAsync(), + x => x.BlogId == blogId, + GetCancellationToken(cancellationToken)); } - public async Task> GetPagedListAsync(Guid blogId, int skipCount, int maxResultCount, string sorting, bool includeDetails = false, CancellationToken cancellationToken = default) + public async Task> 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 queryable = blogPostQueryable - .Where(x => x.BlogId == blogId); + .Where(x => x.BlogId == blogId); if (!sorting.IsNullOrWhiteSpace()) { @@ -51,17 +59,20 @@ namespace Volo.CmsKit.MongoDB.Blogs } queryable = queryable - .Skip(skipCount) - .Take(maxResultCount); + .Skip(skipCount) + .Take(maxResultCount); - return await AsyncExecuter.ToListAsync(queryable, cancellationToken); + return await AsyncExecuter.ToListAsync(queryable, token); } - public async Task SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default) + public async Task 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); } } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs index 2b215d55c6..0cd46a130c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Blogs/MongoBlogRepository.cs @@ -2,6 +2,8 @@ using System; using System.Threading; using System.Threading.Tasks; +using JetBrains.Annotations; +using Volo.Abp; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Blogs; @@ -22,8 +24,9 @@ namespace Volo.CmsKit.MongoDB.Blogs cancellationToken); } - public virtual Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return GetAsync(x => x.Slug == slug, cancellationToken: cancellationToken); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs index fed8fe6e2e..fded228c16 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Contents/MongoContentRepository.cs +++ b/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.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Contents; @@ -11,7 +12,8 @@ namespace Volo.CmsKit.MongoDB.Contents { public class MongoContentRepository : MongoDbRepository, IContentRepository { - public MongoContentRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) + public MongoContentRepository(IMongoDbContextProvider dbContextProvider) : base( + dbContextProvider) { } @@ -21,6 +23,9 @@ namespace Volo.CmsKit.MongoDB.Contents Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return GetAsync(x => x.EntityType == entityType && x.EntityId == entityId && @@ -28,23 +33,30 @@ namespace Volo.CmsKit.MongoDB.Contents cancellationToken: GetCancellationToken(cancellationToken) ); } - + public virtual Task FindAsync( string entityType, string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + return FindAsync(x => x.EntityType == entityType && x.EntityId == entityId && x.TenantId == tenantId, 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 => x.EntityType == entityType && x.EntityId == entityId && @@ -52,8 +64,12 @@ namespace Volo.CmsKit.MongoDB.Contents cancellationToken: GetCancellationToken(cancellationToken)); } - public virtual async Task ExistsAsync([NotNull] string entityType, [NotNull] string entityId, Guid? tenantId = null, CancellationToken cancellationToken = default) + public virtual async Task 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 => x.EntityType == entityType && x.EntityId == entityId && diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs index 66147d0e6d..ec520fe809 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Pages/MongoPageRepository.cs @@ -1,10 +1,12 @@ using System; -using System.Collections.Generic; using System.Linq; using System.Linq.Dynamic.Core; +using JetBrains.Annotations; +using MongoDB.Driver; +using Volo.Abp; +using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; -using MongoDB.Driver; using MongoDB.Driver.Linq; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; @@ -14,14 +16,16 @@ namespace Volo.CmsKit.MongoDB.Pages { public class MongoPageRepository : MongoDbRepository, IPageRepository { - public MongoPageRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) + public MongoPageRepository(IMongoDbContextProvider dbContextProvider) : base( + dbContextProvider) { } - public virtual async Task GetCountAsync(string filter = null, CancellationToken cancellationToken = default) + public virtual async Task GetCountAsync(string filter = null, + CancellationToken cancellationToken = default) { var cancellation = GetCancellationToken(cancellationToken); - + return await (await GetMongoQueryableAsync(cancellation)) .WhereIf>( !filter.IsNullOrWhiteSpace(), @@ -33,12 +37,12 @@ namespace Volo.CmsKit.MongoDB.Pages public virtual async Task> GetListAsync( string filter = null, int maxResultCount = int.MaxValue, - int skipCount = 0, + int skipCount = 0, string sorting = null, CancellationToken cancellationToken = default) { var cancellation = GetCancellationToken(cancellationToken); - + return await (await GetMongoQueryableAsync(cancellation)) .WhereIf>( !filter.IsNullOrWhiteSpace(), @@ -51,19 +55,23 @@ namespace Volo.CmsKit.MongoDB.Pages .ToListAsync(cancellation); } - public virtual Task GetBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task GetBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return GetAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); } - public virtual Task FindBySlugAsync(string slug, CancellationToken cancellationToken = default) + public virtual Task FindBySlugAsync([NotNull]string slug, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(slug, nameof(slug)); return FindAsync(x => x.Slug == slug, cancellationToken: GetCancellationToken(cancellationToken)); } - - public virtual async Task ExistsAsync(string slug, CancellationToken cancellationToken = default) + + public virtual async Task 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)); } } -} +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs index c073f8206f..041b6af5a2 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoEntityTagRepository.cs +++ b/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.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Tags; namespace Volo.CmsKit.MongoDB.Tags { - public class MongoEntityTagRepository: MongoDbRepository, IEntityTagRepository + public class MongoEntityTagRepository : MongoDbRepository, IEntityTagRepository { - public MongoEntityTagRepository(IMongoDbContextProvider dbContextProvider) : base(dbContextProvider) + public MongoEntityTagRepository(IMongoDbContextProvider dbContextProvider) : base( + dbContextProvider) { } public async Task DeleteManyAsync(Guid[] tagIds, CancellationToken cancellationToken = default) { - var collection = await GetCollectionAsync(); - - await collection.DeleteManyAsync(Builders.Filter.In(x => x.TagId, tagIds)); + var token = GetCancellationToken(cancellationToken); + + var collection = await GetCollectionAsync(token); + await collection.DeleteManyAsync(Builders.Filter.In(x => x.TagId, tagIds), token); } public Task FindAsync( @@ -29,11 +32,12 @@ namespace Volo.CmsKit.MongoDB.Tags [CanBeNull] Guid? tenantId, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityId, nameof(entityId)); return base.FindAsync(x => - x.TagId == tagId && - x.EntityId == entityId && - x.TenantId == tenantId, - cancellationToken: cancellationToken); + x.TagId == tagId && + x.EntityId == entityId && + x.TenantId == tenantId, + cancellationToken: GetCancellationToken(cancellationToken)); } } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs b/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs index 02c42c22fb..5e8fdf94a7 100644 --- a/modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Tags/MongoTagRepository.cs +++ b/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.Threading; using System.Threading.Tasks; +using Volo.Abp; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; using Volo.CmsKit.Tags; @@ -24,6 +25,9 @@ namespace Volo.CmsKit.MongoDB.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(name, nameof(name)); + return await (await GetMongoQueryableAsync(cancellationToken)) .AnyAsync(x => x.EntityType == entityType && @@ -51,6 +55,9 @@ namespace Volo.CmsKit.MongoDB.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(name, nameof(name)); + return FindAsync(x => x.EntityType == entityType && x.Name == name && @@ -64,6 +71,9 @@ namespace Volo.CmsKit.MongoDB.Tags Guid? tenantId = null, CancellationToken cancellationToken = default) { + Check.NotNullOrEmpty(entityType, nameof(entityType)); + Check.NotNullOrEmpty(entityId, nameof(entityId)); + var entityTagIds = await (await GetDbContextAsync(cancellationToken)).EntityTags.AsQueryable() .Where(q => q.EntityId == entityId && q.TenantId == tenantId) .Select(q => q.TagId) diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs index ab8270a2a1..9ba368f03d 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Contents/ContentController.cs @@ -1,27 +1,29 @@ using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; using Volo.Abp; +using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Contents; +using Volo.CmsKit.GlobalFeatures; namespace Volo.CmsKit.Public.Contents { - + [RequiresGlobalFeature(typeof(ContentsFeature))] [RemoteService(Name = CmsKitCommonRemoteServiceConsts.RemoteServiceName)] [Area("cms-kit")] [Route("api/cms-kit-public/contents")] public class ContentController : CmsKitControllerBase, IContentPublicAppService { - protected readonly IContentPublicAppService _contentAppService; + protected IContentPublicAppService ContentAppService { get; } public ContentController(IContentPublicAppService contentAppService) { - _contentAppService = contentAppService; + ContentAppService = contentAppService; } [HttpGet] public virtual Task GetAsync(GetContentInput input) { - return _contentAppService.GetAsync(input); + return ContentAppService.GetAsync(input); } } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs index 55041e5c6e..b1f18e2511 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Tags/TagPublicController.cs +++ b/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")] public class TagPublicController : CmsKitPublicControllerBase, ITagAppService { - protected readonly ITagAppService TagAppService; + protected ITagAppService TagAppService { get; } public TagPublicController(ITagAppService tagAppService) {