diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs index e4af45a345..2fbb5bd845 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs @@ -23,5 +23,7 @@ namespace Volo.Blogging.Posts Task UpdateAsync(Guid id, UpdatePostDto input); Task> GetListByUserIdAsync(Guid userId); + + Task> GetLatestBlogPostsAsync(Guid blogId, int count); } } diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs index 0158dc0e5a..939dc29640 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs @@ -195,6 +195,35 @@ namespace Volo.Blogging.Posts return ObjectMapper.Map, List>(posts); } + public async Task> GetLatestBlogPostsAsync(Guid blogId, int count) + { + var posts = await PostRepository.GetLatestBlogPostsAsync(blogId, count); + var userDictionary = new Dictionary(); + var postDtos = new List(ObjectMapper.Map, List>(posts)); + + foreach (var postDto in postDtos) + { + if (postDto.CreatorId.HasValue) + { + if (!userDictionary.ContainsKey(postDto.CreatorId.Value)) + { + var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); + if (creatorUser != null) + { + userDictionary[creatorUser.Id] = ObjectMapper.Map(creatorUser); + } + } + + if (userDictionary.ContainsKey(postDto.CreatorId.Value)) + { + postDto.Writer = userDictionary[(Guid)postDto.CreatorId]; + } + } + } + + return new List(postDtos); + } + [Authorize(BloggingPermissions.Posts.Create)] public async Task CreateAsync(CreatePostDto input) { diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs index 33a6377264..d29d72fc8b 100644 --- a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs @@ -17,5 +17,7 @@ namespace Volo.Blogging.Posts Task> GetOrderedList(Guid blogId,bool descending = false, CancellationToken cancellationToken = default); Task> GetListByUserIdAsync(Guid userId, CancellationToken cancellationToken = default); + + Task> GetLatestBlogPostsAsync(Guid blogId, int count, CancellationToken cancellationToken = default); } } diff --git a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUser.cs b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUser.cs index c7dfa77650..cbe530f11f 100644 --- a/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUser.cs +++ b/modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Users/BlogUser.cs @@ -26,25 +26,25 @@ namespace Volo.Blogging.Users public virtual bool PhoneNumberConfirmed { get; protected set; } [CanBeNull] - public string WebSite { get; set; } + public virtual string WebSite { get; set; } [CanBeNull] - public string Twitter { get; set; } + public virtual string Twitter { get; set; } [CanBeNull] - public string Github { get; set; } + public virtual string Github { get; set; } [CanBeNull] - public string Linkedin { get; set; } + public virtual string Linkedin { get; set; } [CanBeNull] - public string Company { get; set; } + public virtual string Company { get; set; } [CanBeNull] - public string JobTitle { get; set; } + public virtual string JobTitle { get; set; } [CanBeNull] - public string Biography { get; set; } + public virtual string Biography { get; set; } protected BlogUser() { diff --git a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs index 48dfabb77e..98d2d76685 100644 --- a/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs @@ -70,6 +70,15 @@ namespace Volo.Blogging.Posts return await query.ToListAsync(GetCancellationToken(cancellationToken)); } + public async Task> GetLatestBlogPostsAsync(Guid blogId, int count, CancellationToken cancellationToken = default) + { + var query = (await GetDbSetAsync()).Where(p => p.BlogId == blogId) + .OrderByDescending(p => p.CreationTime) + .Take(count); + + return await query.ToListAsync(GetCancellationToken(cancellationToken)); + } + public override async Task> WithDetailsAsync() { return (await GetQueryableAsync()).IncludeDetails(); diff --git a/modules/blogging/src/Volo.Blogging.HttpApi.Client/ClientProxies/PostsClientProxy.Generated.cs b/modules/blogging/src/Volo.Blogging.HttpApi.Client/ClientProxies/PostsClientProxy.Generated.cs index 697606f05c..7f730ee3f2 100644 --- a/modules/blogging/src/Volo.Blogging.HttpApi.Client/ClientProxies/PostsClientProxy.Generated.cs +++ b/modules/blogging/src/Volo.Blogging.HttpApi.Client/ClientProxies/PostsClientProxy.Generated.cs @@ -74,6 +74,15 @@ public partial class PostsClientProxy : ClientProxyBase, IPostA }); } + public Task> GetLatestBlogPostsAsync(Guid blogId, int count) + { + return RequestAsync>(nameof(GetLatestBlogPostsAsync), new ClientProxyRequestTypeValue + { + { typeof(Guid), blogId }, + { typeof(int), count } + }); + } + public virtual async Task DeleteAsync(Guid id) { await RequestAsync(nameof(DeleteAsync), new ClientProxyRequestTypeValue diff --git a/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs b/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs index f2f31261a6..52d7a6426a 100644 --- a/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs +++ b/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs @@ -69,6 +69,13 @@ namespace Volo.Blogging return _postAppService.GetListByUserIdAsync(userId); } + [HttpGet] + [Route("{blogId}/latest/{count}")] + public Task> GetLatestBlogPostsAsync(Guid blogId, int count) + { + return _postAppService.GetLatestBlogPostsAsync(blogId, count); + } + [HttpDelete] [Route("{id}")] public Task DeleteAsync(Guid id) diff --git a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs index be6942eac2..eea6e82015 100644 --- a/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs +++ b/modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs @@ -4,6 +4,7 @@ using System.Threading; using System.Threading.Tasks; using MongoDB.Driver; using MongoDB.Driver.Linq; +using Nito.AsyncEx; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Repositories.MongoDB; using Volo.Abp.MongoDB; @@ -66,5 +67,14 @@ namespace Volo.Blogging.Posts return await query.ToListAsync(GetCancellationToken(cancellationToken)); } + + public async Task> GetLatestBlogPostsAsync(Guid blogId, int count, CancellationToken cancellationToken = default) + { + var query = (await GetMongoQueryableAsync(cancellationToken)).Where(x => x.BlogId == blogId) + .OrderByDescending(x => x.CreationTime) + .Take(count); + + return await query.ToListAsync(GetCancellationToken(cancellationToken)); + } } } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml index a03bd22af3..43ad9abc2f 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml @@ -439,12 +439,12 @@ } else { - @L["LeaveComment"] + @L["LeaveComment"] }

More from @CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Model.Post.Writer.UserName)

- @for (var index = 0; index < Model.PostsList.Count && index <= 5; index++) + @for (var index = 0; index < Model.PostsList.Count; index++) { if (Model.PostsList[index].Id != Model.Post.Id) { diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml.cs b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml.cs index 49bef9c549..54d1a4e71d 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml.cs +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Blogs/Posts/Detail.cshtml.cs @@ -87,7 +87,7 @@ namespace Volo.Blogging.Pages.Blog.Posts Blog = await _blogAppService.GetByShortNameAsync(BlogShortName); Post = await _postAppService.GetForReadingAsync(new GetPostInput { BlogId = Blog.Id, Url = PostUrl }); PostsList = await _postAppService.GetListByUserIdAsync(Post.Writer.Id); - LatestPosts = (await _postAppService.GetListByBlogIdAndTagNameAsync(Blog.Id, TagName)).Items; + LatestPosts = await _postAppService.GetLatestBlogPostsAsync(Blog.Id, 5); CommentsWithReplies = await _commentAppService.GetHierarchicalListOfPostAsync(Post.Id); CountComments(); } diff --git a/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.js b/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.js index c20251820f..75f59564d2 100644 --- a/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.js +++ b/modules/blogging/src/Volo.Blogging.Web/Pages/Members/Index.js @@ -1,8 +1,6 @@ $(function () { - debugger var hash = window.location.hash; if(hash === '#edit-profile'){ - console.log("asdasdsa") $('#all-posts-tab').removeClass('active'); $('#all-posts').removeClass('show').removeClass('active'); $('#edit-profile-tab').addClass('active');