Browse Source

Modified postAppService for getting recent posts

pull/2920/head
AkinCam 6 years ago
parent
commit
eb100ff953
  1. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs
  2. 27
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostDto.cs
  3. 1
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs
  4. 14
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  5. 2
      modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs

2
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/IPostAppService.cs

@ -9,7 +9,7 @@ namespace Volo.Blogging.Posts
{
Task<ListResultDto<PostWithDetailsDto>> GetListByBlogIdAndTagName(Guid blogId, string tagName);
Task<ListResultDto<PostWithDetailsDto>> GetOrderedListPostsByTime();
Task<ListResultDto<PostDto>> GetOrderedListPostsByTime();
Task<PostWithDetailsDto> GetForReadingAsync(GetPostInput input);

27
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<Guid>
{
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; }
}
}

1
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs

@ -18,6 +18,7 @@ namespace Volo.Blogging
CreateMap<Blog, BlogDto>();
CreateMap<BlogUser, BlogUserDto>();
CreateMap<Post, PostWithDetailsDto>().Ignore(x=>x.Writer).Ignore(x=>x.CommentCount).Ignore(x=>x.Tags);
CreateMap<Post, PostDto>().Ignore(x => x.UserName).Ignore(x => x.CommentCount);
CreateMap<Comment, CommentWithDetailsDto>().Ignore(x => x.Writer);
CreateMap<Tag, TagDto>();
}

14
modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs

@ -72,16 +72,22 @@ namespace Volo.Blogging.Posts
return new ListResultDto<PostWithDetailsDto>(postDtos);
}
public async Task<ListResultDto<PostWithDetailsDto>> GetOrderedListPostsByTime()
public async Task<ListResultDto<PostDto>> GetOrderedListPostsByTime()
{
var posts = (await _postRepository.GetListAsync()).OrderByDescending(x => x.CreationTime).ToList();
var postDtos = new List<PostWithDetailsDto>(ObjectMapper.Map<List<Post>, List<PostWithDetailsDto>>(posts));
var postDtos = new List<PostDto>(ObjectMapper.Map<List<Post>, List<PostDto>>(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<BlogUser, BlogUserDto>(creatorUser).UserName;
}
}
return new ListResultDto<PostWithDetailsDto>(postDtos);
return new ListResultDto<PostDto>(postDtos);
}
public async Task<PostWithDetailsDto> GetForReadingAsync(GetPostInput input)

2
modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs

@ -29,7 +29,7 @@ namespace Volo.Blogging
[HttpGet]
public Task<ListResultDto<PostWithDetailsDto>> GetOrderedListPostsByTime()
public Task<ListResultDto<PostDto>> GetOrderedListPostsByTime()
{
return _postAppService.GetOrderedListPostsByTime();
}

Loading…
Cancel
Save