From cf226dca5297bb6f89891c5aeead11c6336dee32 Mon Sep 17 00:00:00 2001 From: Musa Demir Date: Tue, 22 Mar 2022 16:03:56 +0300 Subject: [PATCH] filter by user completed --- .../Volo/CmsKit/Blogs/IBlogPostRepository.cs | 3 ++ .../CmsKit/Blogs/EfCoreBlogPostRepository.cs | 6 +++ .../MongoDB/Blogs/MongoBlogPostRepository.cs | 6 +++ .../Public/Blogs/BlogPostGetListInput.cs | 2 - .../Public/Blogs/IBlogPostPublicAppService.cs | 8 +++- .../Public/Blogs/BlogPostPublicAppService.cs | 12 +++++- .../Public/Blogs/BlogPostPublicController.cs | 15 +++++-- .../Pages/Public/CmsKit/Blogs/BlogPost.cshtml | 4 +- .../Pages/Public/CmsKit/Blogs/Index.cshtml | 39 ++++++++++++++++--- .../Pages/Public/CmsKit/Blogs/Index.cshtml.cs | 13 ++++++- .../Pages/Public/CmsKit/Blogs/index.css | 4 ++ .../Pages/Public/CmsKit/Blogs/index.js | 18 +++++++++ 12 files changed, 113 insertions(+), 17 deletions(-) create mode 100644 modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.js diff --git a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostRepository.cs b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostRepository.cs index 5b04ffee07..6e650113d3 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostRepository.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Blogs/IBlogPostRepository.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Volo.Abp.Domain.Repositories; +using Volo.CmsKit.Users; namespace Volo.CmsKit.Blogs; @@ -25,4 +26,6 @@ public interface IBlogPostRepository : IBasicRepository Task SlugExistsAsync(Guid blogId, string slug, CancellationToken cancellationToken = default); Task GetBySlugAsync(Guid blogId, string slug, CancellationToken cancellationToken = default); + + Task> GetAuthorsHasBlogPosts(CancellationToken cancellationToken = default); } \ No newline at end of file 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 64fe2e2e02..cbd8fa3cfe 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 @@ -97,4 +97,10 @@ public class EfCoreBlogPostRepository : EfCoreRepository x.BlogId == blogId && x.Slug.ToLower() == slug, GetCancellationToken(cancellationToken)); } + + public async Task> GetAuthorsHasBlogPosts(CancellationToken cancellationToken = default) + { + return await (await GetDbContextAsync()).BlogPosts.Select(x => x.Author).Distinct() + .ToListAsync(GetCancellationToken(cancellationToken)); + } } 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 adf394b90f..a2bae9e317 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 @@ -101,4 +101,10 @@ public class MongoBlogPostRepository : MongoDbRepository x.BlogId == blogId && x.Slug.ToLower() == slug, token); } + + public async Task> GetAuthorsHasBlogPosts(CancellationToken cancellationToken = default) + { + var queryable = (await GetQueryableAsync()).Select(x => x.Author).Distinct(); + return await AsyncExecuter.ToListAsync(queryable, GetCancellationToken(cancellationToken)); + } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostGetListInput.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostGetListInput.cs index 82388fdb42..b471171f3b 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostGetListInput.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/BlogPostGetListInput.cs @@ -5,7 +5,5 @@ namespace Volo.CmsKit.Public.Blogs; public class BlogPostGetListInput : PagedAndSortedResultRequestDto { - public string BlogSlug { get; set; } - public Guid? AuthorId { get; set; } } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/IBlogPostPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/IBlogPostPublicAppService.cs index 89103979ba..7f2b50c2a5 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/IBlogPostPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Blogs/IBlogPostPublicAppService.cs @@ -1,13 +1,17 @@ -using JetBrains.Annotations; +using System.Collections.Generic; +using JetBrains.Annotations; using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.Application.Services; +using Volo.CmsKit.Users; namespace Volo.CmsKit.Public.Blogs; public interface IBlogPostPublicAppService : IApplicationService { - Task> GetListAsync(BlogPostGetListInput input); + Task> GetListAsync(string blogSlug, BlogPostGetListInput input); Task GetAsync([NotNull] string blogSlug, [NotNull] string blogPostSlug); + + Task> GetAuthorsHasBlogPosts(); } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs index 39e5e75128..12543b0ed4 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Blogs/BlogPostPublicAppService.cs @@ -5,6 +5,7 @@ using Volo.Abp.Application.Dtos; using Volo.Abp.GlobalFeatures; using Volo.CmsKit.Blogs; using Volo.CmsKit.GlobalFeatures; +using Volo.CmsKit.Users; namespace Volo.CmsKit.Public.Blogs; @@ -14,6 +15,7 @@ public class BlogPostPublicAppService : CmsKitPublicAppServiceBase, IBlogPostPub protected IBlogRepository BlogRepository { get; } protected IBlogPostRepository BlogPostRepository { get; } + public BlogPostPublicAppService( IBlogRepository blogRepository, @@ -32,9 +34,9 @@ public class BlogPostPublicAppService : CmsKitPublicAppServiceBase, IBlogPostPub return ObjectMapper.Map(blogPost); } - public virtual async Task> GetListAsync(BlogPostGetListInput input) + public virtual async Task> GetListAsync(string blogSlug, BlogPostGetListInput input) { - var blog = await BlogRepository.GetBySlugAsync(input.BlogSlug); + var blog = await BlogRepository.GetBySlugAsync(blogSlug); var blogPosts = await BlogPostRepository.GetListAsync(null, blog.Id, input.AuthorId, input.MaxResultCount, input.SkipCount, input.Sorting); @@ -43,4 +45,10 @@ public class BlogPostPublicAppService : CmsKitPublicAppServiceBase, IBlogPostPub await BlogPostRepository.GetCountAsync(blogId: blog.Id), ObjectMapper.Map, List>(blogPosts)); } + + public virtual async Task> GetAuthorsHasBlogPosts() + { + var authors = await BlogPostRepository.GetAuthorsHasBlogPosts(); + return ObjectMapper.Map, List>(authors); + } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Blogs/BlogPostPublicController.cs b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Blogs/BlogPostPublicController.cs index b89939627f..6db900c6ad 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Blogs/BlogPostPublicController.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.HttpApi/Volo/CmsKit/Public/Blogs/BlogPostPublicController.cs @@ -1,11 +1,13 @@ using Microsoft.AspNetCore.Mvc; using System; +using System.Collections.Generic; using System.Threading.Tasks; using Volo.Abp; using Volo.Abp.Application.Dtos; using Volo.Abp.Content; using Volo.Abp.GlobalFeatures; using Volo.CmsKit.GlobalFeatures; +using Volo.CmsKit.Users; namespace Volo.CmsKit.Public.Blogs; @@ -30,8 +32,15 @@ public class BlogPostPublicController : CmsKitPublicControllerBase, IBlogPostPub } [HttpGet] - public virtual Task> GetListAsync(BlogPostGetListInput input) + [Route("{blogSlug}")] + public virtual Task> GetListAsync(string blogSlug, BlogPostGetListInput input) { - return BlogPostPublicAppService.GetListAsync(input); + return BlogPostPublicAppService.GetListAsync(blogSlug, input); } -} + + [HttpGet] + public virtual Task> GetAuthorsHasBlogPosts() + { + return BlogPostPublicAppService.GetAuthorsHasBlogPosts(); + } +} \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml index d8c1f428da..496ce7f8c5 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/BlogPost.cshtml @@ -41,7 +41,9 @@

@Model.BlogPost.Title

- @@@Model.BlogPost.Author?.UserName + + @@@Model.BlogPost.Author?.UserName + @Model.BlogPost.CreationTime

diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml index 32c5585f8e..dbc0d699ef 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml @@ -8,12 +8,40 @@ @model IndexModel @section styles{ - + } + +@section scripts { + + + +} + @{ const string dummyImageSource = "https://dummyimage.com/320x180/a3a3a3/fff.png"; } + + +
+ + +
+
+
@foreach (var blog in Model.Blogs.Items) { @@ -21,16 +49,16 @@ @if (blog.CoverImageMediaId != null) { - + } else { - + }
@blog.Title

- @@@blog.Author?.UserName + @@@blog.Author?.UserName @blog.CreationTime

@blog.ShortDescription

@@ -42,11 +70,10 @@
- }
- + \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs index b93a5d5f40..92c4ff235c 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/Index.cshtml.cs @@ -7,6 +7,7 @@ using System.Threading.Tasks; using Volo.Abp.Application.Dtos; using Volo.Abp.AspNetCore.Mvc.UI.Bootstrap.TagHelpers.Pagination; using Volo.CmsKit.Public.Blogs; +using Volo.CmsKit.Users; namespace Volo.CmsKit.Public.Web.Pages.Public.CmsKit.Blogs; @@ -19,10 +20,16 @@ public class IndexModel : CmsKitPublicPageModelBase [BindProperty(SupportsGet = true)] public int CurrentPage { get; set; } = 1; + + [BindProperty(SupportsGet = true)] + public Guid? AuthorId { get; set; } public PagedResultDto Blogs { get; private set; } public PagerModel PagerModel => new PagerModel(Blogs.TotalCount, Blogs.Items.Count, CurrentPage, PageSize, Request.Path.ToString()); + + [BindProperty(SupportsGet = true)] + public List Authors { get; set; } protected IBlogPostPublicAppService BlogPostPublicAppService { get; } @@ -34,10 +41,14 @@ public class IndexModel : CmsKitPublicPageModelBase public async Task OnGetAsync() { Blogs = await BlogPostPublicAppService.GetListAsync( + BlogSlug, new BlogPostGetListInput { SkipCount = PageSize * (CurrentPage - 1), - MaxResultCount = PageSize + MaxResultCount = PageSize, + AuthorId = AuthorId }); + + Authors = await BlogPostPublicAppService.GetAuthorsHasBlogPosts(); } } diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.css b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.css index 161bb41190..19137de2cb 100644 --- a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.css +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.css @@ -3,4 +3,8 @@ .popover { min-width: 276px; +} + +.author-name-span{ + cursor: pointer; } \ No newline at end of file diff --git a/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.js b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.js new file mode 100644 index 0000000000..0d567d1650 --- /dev/null +++ b/modules/cms-kit/src/Volo.CmsKit.Public.Web/Pages/Public/CmsKit/Blogs/index.js @@ -0,0 +1,18 @@ +$(function () { + var $selectAuthor = $('#AuthorSelect'); + var $authorNameSpan = $('.author-name-span'); + + $selectAuthor.on('change', function () { + var authorId = $selectAuthor.val(); + reloadPageWithQueryString({'authorId': authorId}); + }); + + $authorNameSpan.click(function () { + var authorId = $(this).data('author-id'); + reloadPageWithQueryString({'authorId': authorId}); + }); + + function reloadPageWithQueryString(param) { + window.location.href = window.location.pathname + "?" + $.param(param); + } +});