Browse Source

refactored codes

pull/2920/head
Akın Sabri Çam 7 years ago
parent
commit
40e8165d1d
  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.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs
  4. 1
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/BloggingApplicationAutoMapperProfile.cs
  5. 27
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  6. 1
      modules/blogging/src/Volo.Blogging.Domain.Shared/Volo/Blogging/Blogs/BlogConsts.cs
  7. 2
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs
  8. 13
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs
  9. 6
      modules/blogging/src/Volo.Blogging.HttpApi/Volo/Blogging/PostsController.cs
  10. 5
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.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<PostDto>> GetOrderedListPostsByTime();
Task<ListResultDto<PostWithDetailsDto>> GetTimeOrderedListAsync(Guid blogId);
Task<PostWithDetailsDto> GetForReadingAsync(GetPostInput input);

27
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostDto.cs

@ -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<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.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;

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

@ -18,7 +18,6 @@ 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>();
}

27
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<PostWithDetailsDto>(postDtos);
}
public async Task<ListResultDto<PostDto>> GetOrderedListPostsByTime()
public async Task<ListResultDto<PostWithDetailsDto>> GetTimeOrderedListAsync(Guid blogId)
{
var posts = (await _postRepository.GetListAsync()).OrderByDescending(x => x.CreationTime).ToList();
var postDtos = new List<PostDto>(ObjectMapper.Map<List<Post>, List<PostDto>>(posts));
var posts = await _postRepository.GetOrderedList(blogId);
var postDtos = new List<PostWithDetailsDto>(ObjectMapper.Map<List<Post>, List<PostWithDetailsDto>>(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<BlogUser, BlogUserDto>(creatorUser).UserName;
postDto.Writer = ObjectMapper.Map<BlogUser, BlogUserDto>(creatorUser);
}
}
return new ListResultDto<PostDto>(postDtos);
return new ListResultDto<PostWithDetailsDto>(postDtos);
}
public async Task<PostWithDetailsDto> 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<List<PostWithDetailsDto>> FilterPostsByTag(IEnumerable<PostWithDetailsDto> allPostDtos, Tag tag)
{
var filteredPostDtos = allPostDtos.Where(p => p.Tags?.Any(t => t.Id == tag.Id) ?? false).ToList();
return Task.FromResult(filteredPostDtos);
}
}

1
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";
}
}

2
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostRepository.cs

@ -10,5 +10,7 @@ namespace Volo.Blogging.Posts
Task<List<Post>> GetPostsByBlogId(Guid id);
Task<Post> GetPostByUrl(Guid blogId, string url);
Task<List<Post>> GetOrderedList(Guid blogId,bool descending = false);
}
}

13
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostRepository.cs

@ -35,6 +35,19 @@ namespace Volo.Blogging.Posts
return post;
}
public async Task<List<Post>> 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<Post> WithDetails()
{
return GetQueryable().IncludeDetails();

6
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<ListResultDto<PostDto>> GetOrderedListPostsByTime()
[Route("{blogId}/all/by-time")]
public Task<ListResultDto<PostWithDetailsDto>> GetTimeOrderedListAsync(Guid blogId)
{
return _postAppService.GetOrderedListPostsByTime();
return _postAppService.GetTimeOrderedListAsync(blogId);
}
[HttpGet]

5
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostRepository.cs

@ -32,5 +32,10 @@ namespace Volo.Blogging.Posts
return post;
}
public Task<List<Post>> GetOrderedList(Guid blogId, bool @descending = false)
{
throw new NotImplementedException();
}
}
}

Loading…
Cancel
Save