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 b28c184ce7..55b64d29de 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 @@ -9,7 +9,7 @@ namespace Volo.Blogging.Posts { Task> GetListByBlogIdAndTagName(Guid blogId, string tagName); - Task> GetOrderedListPostsByTime(); + Task> GetTimeOrderedListAsync(Guid blogId); Task GetForReadingAsync(GetPostInput input); diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostDto.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostDto.cs deleted file mode 100644 index a4d4364a96..0000000000 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostDto.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Volo.Abp.Application.Dtos; - -namespace Volo.Blogging.Posts -{ - public class PostDto : FullAuditedEntityDto - { - public Guid BlogId { get; set; } - - public string Title { get; set; } - - public string CoverImage { get; set; } - - public string Url { get; set; } - - public string Content { get; set; } - - public string UserName { get; set; } - - public int ReadCount { get; set; } - - public int CommentCount { get; set; } - - } -} diff --git a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs index 08dde7e019..ff831031aa 100644 --- a/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Reflection; using JetBrains.Annotations; using Volo.Abp.Application.Dtos; using Volo.Blogging.Tagging.Dtos; diff --git a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs index a018a318ae..b9e3cf0dea 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs @@ -18,7 +18,6 @@ namespace Volo.Blogging CreateMap(); CreateMap(); CreateMap().Ignore(x=>x.Writer).Ignore(x=>x.CommentCount).Ignore(x=>x.Tags); - CreateMap().Ignore(x => x.UserName).Ignore(x => x.CommentCount); CreateMap().Ignore(x => x.Writer); CreateMap(); } 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 d0bd0802e5..44b8e9866e 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 @@ -44,11 +44,6 @@ namespace Volo.Blogging.Posts postDtos = await FilterPostsByTag(postDtos, tag); } - foreach (var postDto in postDtos) - { - postDto.CommentCount = await _commentRepository.GetCommentCountOfPostAsync(postDto.Id); - } - foreach (var postDto in postDtos) { if (postDto.CreatorId.HasValue) @@ -68,26 +63,26 @@ namespace Volo.Blogging.Posts } } } - + return new ListResultDto(postDtos); } - public async Task> GetOrderedListPostsByTime() + public async Task> GetTimeOrderedListAsync(Guid blogId) { - var posts = (await _postRepository.GetListAsync()).OrderByDescending(x => x.CreationTime).ToList(); - var postDtos = new List(ObjectMapper.Map, List>(posts)); + var posts = await _postRepository.GetOrderedList(blogId); + + var postDtos = new List(ObjectMapper.Map, List>(posts)); foreach (var postDto in postDtos) { - if (postDto.CreatorId.HasValue) + var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); + if (creatorUser != null) { - var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); - - postDto.UserName = ObjectMapper.Map(creatorUser).UserName; + postDto.Writer = ObjectMapper.Map(creatorUser); } } - return new ListResultDto(postDtos); + return new ListResultDto(postDtos); } public async Task GetForReadingAsync(GetPostInput input) @@ -190,7 +185,7 @@ namespace Volo.Blogging.Posts { var postList = await _postRepository.GetListAsync(); - if (postList.Where(p => p.Url == url).WhereIf(existingPost != null, p => existingPost.Id != p.Id).Any()) + if (postList.Where(p => p.Url == url).WhereIf(existingPost != null, p => existingPost.Id != p.Id).Any()) { return url + "-" + Guid.NewGuid().ToString().Substring(0, 5); } @@ -270,7 +265,7 @@ namespace Volo.Blogging.Posts private Task> FilterPostsByTag(IEnumerable allPostDtos, Tag tag) { var filteredPostDtos = allPostDtos.Where(p => p.Tags?.Any(t => t.Id == tag.Id) ?? false).ToList(); - + return Task.FromResult(filteredPostDtos); } } diff --git a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Blogs/BlogConsts.cs b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Blogs/BlogConsts.cs index b9613b5a4e..bb107e7971 100644 --- a/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Blogs/BlogConsts.cs +++ b/modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Blogs/BlogConsts.cs @@ -8,5 +8,6 @@ public const int MaxDescriptionLength = 1024; + public const string BlogName = "blog"; } } 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 d38cd5c0d7..02bd68a6b0 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 @@ -10,5 +10,7 @@ namespace Volo.Blogging.Posts Task> GetPostsByBlogId(Guid id); Task GetPostByUrl(Guid blogId, string url); + + Task> GetOrderedList(Guid blogId,bool descending = false); } } 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 fd4bec2de4..01c5652902 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 @@ -35,6 +35,19 @@ namespace Volo.Blogging.Posts return post; } + public async Task> GetOrderedList(Guid blogId,bool descending = false) + { + if (!descending) + { + return await DbSet.Where(x=>x.BlogId==blogId).OrderByDescending(x => x.CreationTime).ToListAsync(); + } + else + { + return await DbSet.Where(x => x.BlogId == blogId).OrderBy(x => x.CreationTime).ToListAsync(); + } + + } + public override IQueryable WithDetails() { return GetQueryable().IncludeDetails(); 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 c320744f96..332f60c256 100644 --- a/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs +++ b/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs @@ -27,11 +27,11 @@ namespace Volo.Blogging return _postAppService.GetListByBlogIdAndTagName(blogId, tagName); } - [HttpGet] - public Task> GetOrderedListPostsByTime() + [Route("{blogId}/all/by-time")] + public Task> GetTimeOrderedListAsync(Guid blogId) { - return _postAppService.GetOrderedListPostsByTime(); + return _postAppService.GetTimeOrderedListAsync(blogId); } [HttpGet] 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 52a614df90..223aa8968e 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 @@ -32,5 +32,10 @@ namespace Volo.Blogging.Posts return post; } + + public Task> GetOrderedList(Guid blogId, bool @descending = false) + { + throw new NotImplementedException(); + } } }