From eb100ff9537d2d394a17cb9694d69f9b3b2c5fa5 Mon Sep 17 00:00:00 2001 From: AkinCam <172804016@ogr.cbu.edu.tr> Date: Tue, 25 Feb 2020 23:29:04 +0300 Subject: [PATCH] Modified postAppService for getting recent posts --- .../Volo/Blogging/Posts/IPostAppService.cs | 2 +- .../Volo/Blogging/Posts/PostDto.cs | 27 +++++++++++++++++++ .../BloggingApplicationAutoMapperProfile.cs | 1 + .../Volo/Blogging/Posts/PostAppService.cs | 14 +++++++--- .../Volo/Blogging/PostsController.cs | 2 +- 5 files changed, 40 insertions(+), 6 deletions(-) create mode 100644 modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostDto.cs 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 c16a8903e8..b28c184ce7 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> GetOrderedListPostsByTime(); 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 new file mode 100644 index 0000000000..a4d4364a96 --- /dev/null +++ b/modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostDto.cs @@ -0,0 +1,27 @@ +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/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs index b9e3cf0dea..a018a318ae 100644 --- a/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs +++ b/modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs @@ -18,6 +18,7 @@ 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 a23309a33a..d0bd0802e5 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 @@ -72,16 +72,22 @@ namespace Volo.Blogging.Posts return new ListResultDto(postDtos); } - public async Task> GetOrderedListPostsByTime() + public async Task> GetOrderedListPostsByTime() { var posts = (await _postRepository.GetListAsync()).OrderByDescending(x => x.CreationTime).ToList(); - var postDtos = new List(ObjectMapper.Map, List>(posts)); + var postDtos = new List(ObjectMapper.Map, List>(posts)); foreach (var postDto in postDtos) { - postDto.Tags = await GetTagsOfPost(postDto.Id); + if (postDto.CreatorId.HasValue) + { + var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); + + postDto.UserName = ObjectMapper.Map(creatorUser).UserName; + } } - return new ListResultDto(postDtos); + + return new ListResultDto(postDtos); } public async Task GetForReadingAsync(GetPostInput input) 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 1b465f83c2..c320744f96 100644 --- a/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs +++ b/modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs @@ -29,7 +29,7 @@ namespace Volo.Blogging [HttpGet] - public Task> GetOrderedListPostsByTime() + public Task> GetOrderedListPostsByTime() { return _postAppService.GetOrderedListPostsByTime(); }