Browse Source

Merge pull request #7 from abpframework/master

merge
pull/786/head
Marcelo Mohr Maciel 7 years ago
committed by GitHub
parent
commit
4f76f583d3
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      modules/blogging/src/Volo.Blogging.Application/Volo/Blogging/Posts/PostAppService.cs
  2. 13
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostTagRepository.cs
  3. 11
      modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/Post.cs
  4. 28
      modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostTagRepository.cs
  5. 2
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/BloggingMongoDbContext.cs
  6. 5
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/BloggingMongoDbContextExtensions.cs
  7. 1
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/BloggingMongoDbModule.cs
  8. 2
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/IBloggingMongoDbContext.cs
  9. 30
      modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostTagRepository.cs
  10. 1
      samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingService.Host.csproj
  11. 2
      samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs

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

@ -24,15 +24,13 @@ namespace Volo.Blogging.Posts
private readonly IPostRepository _postRepository;
private readonly ITagRepository _tagRepository;
private readonly IPostTagRepository _postTagRepository;
private readonly ICommentRepository _commentRepository;
public PostAppService(IPostRepository postRepository, ITagRepository tagRepository, IPostTagRepository postTagRepository, ICommentRepository commentRepository, IBlogUserLookupService userLookupService)
public PostAppService(IPostRepository postRepository, ITagRepository tagRepository, ICommentRepository commentRepository, IBlogUserLookupService userLookupService)
{
UserLookupService = userLookupService;
_postRepository = postRepository;
_tagRepository = tagRepository;
_postTagRepository = postTagRepository;
_commentRepository = commentRepository;
}
@ -85,10 +83,11 @@ namespace Volo.Blogging.Posts
private async Task<List<PostWithDetailsDto>> FilterPostsByTag(List<PostWithDetailsDto> allPostDtos, Tag tag)
{
var filteredPostDtos = new List<PostWithDetailsDto>();
var posts = await _postRepository.GetListAsync();
foreach (var postDto in allPostDtos)
{
if (await _postTagRepository.FindByTagIdAndPostIdAsync(postDto.Id, tag.Id) == null)
if (!postDto.Tags.Any(p=> p.Id == tag.Id))
{
continue;
}
@ -145,7 +144,6 @@ namespace Volo.Blogging.Posts
var tags = await GetTagsOfPost(id);
_tagRepository.DecreaseUsageCountOfTags(tags.Select(t => t.Id).ToList());
_postTagRepository.DeleteOfPost(id);
await _commentRepository.DeleteOfPost(id);
await _postRepository.DeleteAsync(id);
@ -210,7 +208,6 @@ namespace Volo.Blogging.Posts
private async Task SaveTags(List<String> newTags, Post post)
{
await RemoveOldTags(newTags, post);
await AddNewTags(newTags, post);
@ -218,9 +215,7 @@ namespace Volo.Blogging.Posts
private async Task RemoveOldTags(List<string> newTags, Post post)
{
var oldTags = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == post.Id).ToList();
foreach (var oldTag in oldTags)
foreach (var oldTag in post.Tags)
{
var tag = await _tagRepository.GetAsync(oldTag.TagId);
@ -228,7 +223,7 @@ namespace Volo.Blogging.Posts
if (oldTagNameInNewTags == null)
{
await _postTagRepository.DeleteAsync(oldTag);
post.RemoveTag(oldTag.TagId);
tag.DecreaseUsageCount();
await _tagRepository.UpdateAsync(tag);
@ -256,15 +251,14 @@ namespace Volo.Blogging.Posts
{
tag.IncreaseUsageCount();
tag = await _tagRepository.UpdateAsync(tag);
post.AddTag(tag.Id);
}
await _postTagRepository.InsertAsync(new PostTag(post.Id, tag.Id));
}
}
private async Task<List<TagDto>> GetTagsOfPost(Guid id)
{
var tagIds = (await _postTagRepository.GetListAsync()).Where(pt => pt.PostId == id);
var tagIds = (await _postRepository.GetAsync(id)).Tags;
var tags = await _tagRepository.GetListAsync(tagIds.Select(t => t.TagId));

13
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/IPostTagRepository.cs

@ -1,13 +0,0 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;
namespace Volo.Blogging.Posts
{
public interface IPostTagRepository : IBasicRepository<PostTag>
{
void DeleteOfPost(Guid id);
Task<PostTag> FindByTagIdAndPostIdAsync(Guid postId, Guid tagId);
}
}

11
modules/blogging/src/Volo.Blogging.Domain/Volo/Blogging/Posts/Post.cs

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using JetBrains.Annotations;
using Volo.Abp;
@ -61,5 +62,15 @@ namespace Volo.Blogging.Posts
Url = Check.NotNullOrWhiteSpace(url, nameof(url));
return this;
}
public virtual void AddTag(Guid tagId)
{
Tags.Add(new PostTag(Id,tagId));
}
public virtual void RemoveTag(Guid tagId)
{
Tags.RemoveAll(t => t.TagId == tagId);
}
}
}

28
modules/blogging/src/Volo.Blogging.EntityFrameworkCore/Volo/Blogging/Posts/EfCorePostTagRepository.cs

@ -1,28 +0,0 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Volo.Abp.Domain.Repositories.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore;
using Volo.Blogging.EntityFrameworkCore;
namespace Volo.Blogging.Posts
{
public class EfCorePostTagRepository : EfCoreRepository<IBloggingDbContext, PostTag>, IPostTagRepository
{
public EfCorePostTagRepository(IDbContextProvider<IBloggingDbContext> dbContextProvider) : base(dbContextProvider)
{
}
public void DeleteOfPost(Guid id)
{
var recordsToDelete = DbSet.Where(pt=>pt.PostId == id);
DbSet.RemoveRange(recordsToDelete);
}
public async Task<PostTag> FindByTagIdAndPostIdAsync(Guid postId, Guid tagId)
{
return await DbSet.FirstOrDefaultAsync(pt=> pt.PostId == postId && pt.TagId == tagId);
}
}
}

2
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/BloggingMongoDbContext.cs

@ -24,8 +24,6 @@ namespace Volo.Blogging.MongoDB
public IMongoCollection<Tagging.Tag> Tags => Collection<Tagging.Tag>();
public IMongoCollection<PostTag> PostTags => Collection<PostTag>();
public IMongoCollection<Comment> Comments => Collection<Comment>();
protected override void CreateModel(IMongoModelBuilder modelBuilder)

5
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/BloggingMongoDbContextExtensions.cs

@ -42,11 +42,6 @@ namespace Volo.Blogging.MongoDB
b.CollectionName = options.CollectionPrefix + "Tags";
});
builder.Entity<PostTag>(b =>
{
b.CollectionName = options.CollectionPrefix + "PostTags";
});
builder.Entity<Comment>(b =>
{
b.CollectionName = options.CollectionPrefix + "Comments";

1
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/BloggingMongoDbModule.cs

@ -23,7 +23,6 @@ namespace Volo.Blogging.MongoDB
options.AddRepository<BlogUser, MongoBlogUserRepository>();
options.AddRepository<Post, MongoPostRepository>();
options.AddRepository<Tag, MongoTagRepository>();
options.AddRepository<PostTag, MongoPostTagRepository>();
options.AddRepository<Comment, MongoCommentRepository>();
});
}

2
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/MongoDB/IBloggingMongoDbContext.cs

@ -19,8 +19,6 @@ namespace Volo.Blogging.MongoDB
IMongoCollection<Tagging.Tag> Tags { get; }
IMongoCollection<PostTag> PostTags { get; }
IMongoCollection<Comment> Comments { get; }
}

30
modules/blogging/src/Volo.Blogging.MongoDB/Volo/Blogging/Posts/MongoPostTagRepository.cs

@ -1,30 +0,0 @@
using System;
using System.Threading.Tasks;
using MongoDB.Driver.Linq;
using Volo.Abp.Domain.Repositories.MongoDB;
using Volo.Abp.MongoDB;
using Volo.Blogging.MongoDB;
namespace Volo.Blogging.Posts
{
public class MongoPostTagRepository : MongoDbRepository<IBloggingMongoDbContext, PostTag>, IPostTagRepository
{
public MongoPostTagRepository(IMongoDbContextProvider<IBloggingMongoDbContext> dbContextProvider) : base(dbContextProvider)
{
}
public void DeleteOfPost(Guid id)
{
var recordsToDelete = GetMongoQueryable().Where(pt => pt.PostId == id);
foreach (var record in recordsToDelete)
{
Delete(record);
}
}
public async Task<PostTag> FindByTagIdAndPostIdAsync(Guid postId, Guid tagId)
{
return await GetMongoQueryable().FirstOrDefaultAsync(pt => pt.PostId == postId && pt.TagId == tagId);
}
}
}

1
samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingService.Host.csproj

@ -24,6 +24,7 @@
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Autofac\Volo.Abp.Autofac.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.EventBus.RabbitMQ\Volo.Abp.EventBus.RabbitMQ.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.Http.Client.IdentityModel\Volo.Abp.Http.Client.IdentityModel.csproj" />
<ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.HttpApi.Client\Volo.Abp.Identity.HttpApi.Client.csproj" />
<ProjectReference Include="..\..\..\..\modules\blogging\src\Volo.Blogging.HttpApi\Volo.Blogging.HttpApi.csproj" />
<ProjectReference Include="..\..\..\..\modules\blogging\src\Volo.Blogging.MongoDB\Volo.Blogging.MongoDB.csproj" />

2
samples/MicroserviceDemo/microservices/BloggingService.Host/BloggingServiceHostModule.cs

@ -10,6 +10,7 @@ using Volo.Abp.EntityFrameworkCore;
using Volo.Abp.EntityFrameworkCore.SqlServer;
using Volo.Abp.EventBus.RabbitMq;
using Volo.Abp.Guids;
using Volo.Abp.Http.Client.IdentityModel;
using Volo.Abp.Identity;
using Volo.Abp.Localization;
using Volo.Abp.Modularity;
@ -33,6 +34,7 @@ namespace BloggingService.Host
typeof(BloggingHttpApiModule),
typeof(BloggingMongoDbModule),
typeof(BloggingApplicationModule),
typeof(AbpHttpClientIdentityModelModule),
typeof(AbpIdentityHttpApiClientModule)
)]
public class BloggingServiceHostModule : AbpModule

Loading…
Cancel
Save