Browse Source

Bloggin module improvements

pull/441/head
Yunus Emre Kalkan 8 years ago
parent
commit
58b77f1d09
  1. 24
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/BlogUserDto.cs
  2. 2
      modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/PostWithDetailsDto.cs
  3. 37
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  4. 2
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/ITagRepository.cs
  5. 5
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs
  6. 1
      modules/blogging/src/Volo.Blogging.Web/AbpBloggingWebAutoMapperProfile.cs

24
modules/blogging/src/Volo.Blogging.Application.Contracts/Volo/Blogging/Posts/BlogUserDto.cs

@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Text;
using Volo.Abp.Application.Dtos;
namespace Volo.Blogging.Posts
{
public class BlogUserDto : EntityDto<Guid>
{
public Guid? TenantId { get; set; }
public string UserName { get; set; }
public string Email { get; set; }
public bool EmailConfirmed { get; set; }
public string PhoneNumber { get; set; }
public bool PhoneNumberConfirmed { get; set; }
public Dictionary<string, object> ExtraProperties { get; set; }
}
}

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

@ -21,6 +21,8 @@ namespace Volo.Blogging.Posts
public int CommentCount { get; set; } public int CommentCount { get; set; }
public BlogUserDto Writer { get; set; }
public List<TagDto> Tags { get; set; } public List<TagDto> Tags { get; set; }
} }
} }

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

@ -41,30 +41,51 @@ namespace Volo.Blogging.Posts
{ {
var posts = _postRepository.GetPostsByBlogId(id); var posts = _postRepository.GetPostsByBlogId(id);
var postDtos = new List<PostWithDetailsDto>( var tag = tagName.IsNullOrWhiteSpace()? null: await _tagRepository.GetByNameAsync(tagName);
var allPostDtos = new List<PostWithDetailsDto>(
ObjectMapper.Map<List<Post>, List<PostWithDetailsDto>>(posts)); ObjectMapper.Map<List<Post>, List<PostWithDetailsDto>>(posts));
foreach (var postDto in postDtos) var filteredPostDtos = new List<PostWithDetailsDto>();
var userDictionary = new Dictionary<Guid, BlogUserDto>();
foreach (var postDto in allPostDtos)
{ {
postDto.Tags = await GetTagsOfPost(postDto.Id); postDto.Tags = await GetTagsOfPost(postDto.Id);
if (tag != null && postDto.Tags.All(t => t.Id != tag.Id))
{
continue;
}
filteredPostDtos.Add(postDto);
}
foreach (var postDto in filteredPostDtos)
{
postDto.CommentCount = await _commentRepository.GetCommentCountOfPostAsync(postDto.Id); postDto.CommentCount = await _commentRepository.GetCommentCountOfPostAsync(postDto.Id);
if (postDto.CreatorId.HasValue) if (postDto.CreatorId.HasValue)
{ {
var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value); var creatorUser = await UserLookupService.FindByIdAsync(postDto.CreatorId.Value);
//TODO: Check if creatorUser is null!
Logger.LogWarning($"Creator of post {postDto.Id} is {creatorUser.UserName}"); if (creatorUser != null && !userDictionary.ContainsKey(creatorUser.Id))
{
userDictionary.Add(creatorUser.Id, ObjectMapper.Map<BlogUser, BlogUserDto>(creatorUser));
}
} }
} }
if (!tagName.IsNullOrWhiteSpace()) foreach (var postDto in filteredPostDtos)
{ {
var tag = await _tagRepository.GetByNameAsync(tagName); if (postDto.CreatorId.HasValue && userDictionary.ContainsKey((Guid) postDto.CreatorId))
postDtos = postDtos.Where(p => p.Tags.Any(t => t.Id == tag.Id)).ToList(); {
postDto.Writer = userDictionary[(Guid)postDto.CreatorId];
}
} }
return new ListResultDto<PostWithDetailsDto>(postDtos); return new ListResultDto<PostWithDetailsDto>(allPostDtos);
} }
public async Task<PostWithDetailsDto> GetForReadingAsync(GetPostInput input) public async Task<PostWithDetailsDto> GetForReadingAsync(GetPostInput input)

2
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Tagging/ITagRepository.cs

@ -11,6 +11,8 @@ namespace Volo.Blogging.Tagging
Task<Tag> GetByNameAsync(string name); Task<Tag> GetByNameAsync(string name);
Task<Tag> FindByNameAsync(string name);
Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids); Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids);
void DecreaseUsageCountOfTags(List<Guid> id); void DecreaseUsageCountOfTags(List<Guid> id);

5
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Tagging/EfCoreTagRepository.cs

@ -22,6 +22,11 @@ namespace Volo.Blogging.Tagging
} }
public async Task<Tag> GetByNameAsync(string name) public async Task<Tag> GetByNameAsync(string name)
{
return await DbSet.FirstAsync(t=>t.Name == name);
}
public async Task<Tag> FindByNameAsync(string name)
{ {
return await DbSet.FirstOrDefaultAsync(t=>t.Name == name); return await DbSet.FirstOrDefaultAsync(t=>t.Name == name);
} }

1
modules/blogging/src/Volo.Blogging.Web/AbpBloggingWebAutoMapperProfile.cs

@ -16,7 +16,6 @@ namespace Volo.Blogging
{ {
CreateMap<PostWithDetailsDto, EditPostViewModel>().Ignore(x=>x.Tags); CreateMap<PostWithDetailsDto, EditPostViewModel>().Ignore(x=>x.Tags);
CreateMap<NewModel.CreatePostViewModel, CreatePostDto>(); CreateMap<NewModel.CreatePostViewModel, CreatePostDto>();
CreateMap<IndexModel.BlogIndexViewModel, CreateBlogDto>();
CreateMap<CreateModel.BlogCreateModalView, CreateBlogDto>(); CreateMap<CreateModel.BlogCreateModalView, CreateBlogDto>();
CreateMap<BlogDto, EditModel.BlogEditViewModel>(); CreateMap<BlogDto, EditModel.BlogEditViewModel>();
} }

Loading…
Cancel
Save