mirror of https://github.com/abpframework/abp.git
24 changed files with 523 additions and 11 deletions
@ -0,0 +1,15 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp2.1</TargetFramework> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\..\src\Volo.Blogging.MongoDB\Volo.Blogging.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\modules\permission-management\src\Volo.Abp.PermissionManagement.MongoDB\Volo.Abp.PermissionManagement.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\modules\setting-management\src\Volo.Abp.SettingManagement.MongoDB\Volo.Abp.SettingManagement.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\modules\identity\src\Volo.Abp.Identity.MongoDB\Volo.Abp.Identity.MongoDB.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,21 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using Volo.Abp.Identity.MongoDB; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.PermissionManagement.MongoDB; |
||||
|
using Volo.Abp.SettingManagement.MongoDB; |
||||
|
using Volo.Blogging.MongoDB; |
||||
|
|
||||
|
namespace Volo.BloggingTestApp.MongoDb |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(AbpIdentityMongoDbModule), |
||||
|
typeof(BloggingMongoDbModule), |
||||
|
typeof(AbpSettingManagementMongoDbModule), |
||||
|
typeof(AbpPermissionManagementMongoDbModule) |
||||
|
)] |
||||
|
public class BloggingTestAppMongoDbModule : AbpModule |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFramework>netcoreapp2.1</TargetFramework> |
||||
|
<AssemblyName>Volo.Blogging.MongoDB</AssemblyName> |
||||
|
<PackageId>Volo.Blogging.MongoDB</PackageId> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Blogging.Domain\Volo.Blogging.Domain.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.MongoDB\Volo.Abp.MongoDB.csproj" /> |
||||
|
<ProjectReference Include="..\..\..\users\src\Volo.Abp.Users.MongoDB\Volo.Abp.Users.MongoDB.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,38 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Blogging.MongoDB; |
||||
|
using System.Linq; |
||||
|
using System.Linq.Dynamic.Core; |
||||
|
|
||||
|
namespace Volo.Blogging.Blogs |
||||
|
{ |
||||
|
public class MongoBlogRepository : MongoDbRepository<IBloggingMongoDbContext, Blog, Guid>, IBlogRepository |
||||
|
{ |
||||
|
public MongoBlogRepository(IMongoDbContextProvider<IBloggingMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<Blog> FindByShortNameAsync(string shortName) |
||||
|
{ |
||||
|
return await GetMongoQueryable().FirstOrDefaultAsync(p => p.ShortName == shortName); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<Blog>> GetListAsync(string sorting, int maxResultCount, int skipCount) |
||||
|
{ |
||||
|
var auditLogs = GetMongoQueryable().OrderBy(sorting ?? "creationTime desc").As<IMongoQueryable<Blog>>() |
||||
|
.PageBy(skipCount, maxResultCount) |
||||
|
.ToList(); |
||||
|
|
||||
|
return auditLogs; |
||||
|
} |
||||
|
|
||||
|
public async Task<int> GetTotalCount() |
||||
|
{ |
||||
|
return await GetMongoQueryable().CountAsync(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,49 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Blogging.MongoDB; |
||||
|
|
||||
|
namespace Volo.Blogging.Comments |
||||
|
{ |
||||
|
public class MongoCommentRepository : MongoDbRepository<IBloggingMongoDbContext, Comment, Guid>, ICommentRepository |
||||
|
{ |
||||
|
public MongoCommentRepository(IMongoDbContextProvider<IBloggingMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<List<Comment>> GetListOfPostAsync(Guid postId) |
||||
|
{ |
||||
|
return await GetMongoQueryable() |
||||
|
.Where(a => a.PostId == postId) |
||||
|
.OrderBy(a => a.CreationTime) |
||||
|
.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
public async Task<int> GetCommentCountOfPostAsync(Guid postId) |
||||
|
{ |
||||
|
return await GetMongoQueryable() |
||||
|
.CountAsync(a => a.PostId == postId); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<Comment>> GetRepliesOfComment(Guid id) |
||||
|
{ |
||||
|
return await GetMongoQueryable() |
||||
|
.Where(a => a.RepliedCommentId == id).ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
public async Task DeleteOfPost(Guid id) |
||||
|
{ |
||||
|
var recordsToDelete = GetMongoQueryable().Where(pt => pt.PostId == id); |
||||
|
|
||||
|
foreach (var record in recordsToDelete) |
||||
|
{ |
||||
|
await DeleteAsync(record); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using MongoDB.Bson.Serialization; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.Threading; |
||||
|
using Volo.Blogging.Users; |
||||
|
|
||||
|
namespace Volo.Blogging.MongoDB |
||||
|
{ |
||||
|
public static class AbpBloggingBsonClassMap |
||||
|
{ |
||||
|
private static readonly OneTimeRunner OneTimeRunner = new OneTimeRunner(); |
||||
|
|
||||
|
public static void Configure() |
||||
|
{ |
||||
|
OneTimeRunner.Run(() => |
||||
|
{ |
||||
|
BsonClassMap.RegisterClassMap<BlogUser>(map => |
||||
|
{ |
||||
|
map.AutoMap(); |
||||
|
map.ConfigureExtraProperties(); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,41 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using MongoDB.Driver; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Blogging.Blogs; |
||||
|
using Volo.Blogging.Comments; |
||||
|
using Volo.Blogging.Posts; |
||||
|
using Volo.Blogging.Users; |
||||
|
|
||||
|
namespace Volo.Blogging.MongoDB |
||||
|
{ |
||||
|
[ConnectionStringName("Blogging")] |
||||
|
public class BloggingMongoDbContext : AbpMongoDbContext, IBloggingMongoDbContext |
||||
|
{ |
||||
|
public static string CollectionPrefix { get; set; } = BloggingConsts.DefaultDbTablePrefix; |
||||
|
|
||||
|
public IMongoCollection<BlogUser> Users => Collection<BlogUser>(); |
||||
|
|
||||
|
public IMongoCollection<Blog> Blogs => Collection<Blog>(); |
||||
|
|
||||
|
public IMongoCollection<Post> Posts => Collection<Post>(); |
||||
|
|
||||
|
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) |
||||
|
{ |
||||
|
base.CreateModel(modelBuilder); |
||||
|
|
||||
|
modelBuilder.ConfigureBlogging(options => |
||||
|
{ |
||||
|
options.CollectionPrefix = CollectionPrefix; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,56 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Blogging.Blogs; |
||||
|
using Volo.Blogging.Comments; |
||||
|
using Volo.Blogging.Posts; |
||||
|
using Volo.Blogging.Users; |
||||
|
|
||||
|
namespace Volo.Blogging.MongoDB |
||||
|
{ |
||||
|
public static class BloggingMongoDbContextExtensions |
||||
|
{ |
||||
|
public static void ConfigureBlogging( |
||||
|
this IMongoModelBuilder builder, |
||||
|
Action<MongoModelBuilderConfigurationOptions> optionsAction = null) |
||||
|
{ |
||||
|
Check.NotNull(builder, nameof(builder)); |
||||
|
|
||||
|
var options = new BloggingMongoModelBuilderConfigurationOptions(); |
||||
|
|
||||
|
optionsAction?.Invoke(options); |
||||
|
|
||||
|
builder.Entity<BlogUser>(b => |
||||
|
{ |
||||
|
b.CollectionName = options.CollectionPrefix + "Users"; |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<Blog>(b => |
||||
|
{ |
||||
|
b.CollectionName = options.CollectionPrefix + "Blogs"; |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<Post>(b => |
||||
|
{ |
||||
|
b.CollectionName = options.CollectionPrefix + "Posts"; |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<Tagging.Tag>(b => |
||||
|
{ |
||||
|
b.CollectionName = options.CollectionPrefix + "Tags"; |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<PostTag>(b => |
||||
|
{ |
||||
|
b.CollectionName = options.CollectionPrefix + "PostTags"; |
||||
|
}); |
||||
|
|
||||
|
builder.Entity<Comment>(b => |
||||
|
{ |
||||
|
b.CollectionName = options.CollectionPrefix + "Comments"; |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.Users.MongoDB; |
||||
|
using Volo.Blogging.Blogs; |
||||
|
using Volo.Blogging.Comments; |
||||
|
using Volo.Blogging.Posts; |
||||
|
using Volo.Blogging.Tagging; |
||||
|
using Volo.Blogging.Users; |
||||
|
|
||||
|
namespace Volo.Blogging.MongoDB |
||||
|
{ |
||||
|
[DependsOn( |
||||
|
typeof(BloggingDomainModule), |
||||
|
typeof(AbpUsersMongoDbModule) |
||||
|
)] |
||||
|
public class BloggingMongoDbModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
AbpBloggingBsonClassMap.Configure(); |
||||
|
|
||||
|
context.Services.AddMongoDbContext<BloggingMongoDbContext>(options => |
||||
|
{ |
||||
|
options.AddRepository<Blog, MongoBlogRepository>(); |
||||
|
options.AddRepository<BlogUser, MongoBlogUserRepository>(); |
||||
|
options.AddRepository<Post, MongoPostRepository>(); |
||||
|
options.AddRepository<Tag, MongoTagRepository>(); |
||||
|
options.AddRepository<PostTag, MongoPostTagRepository>(); |
||||
|
options.AddRepository<Comment, MongoCommentRepository>(); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,16 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Text; |
||||
|
using JetBrains.Annotations; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
|
||||
|
namespace Volo.Blogging.MongoDB |
||||
|
{ |
||||
|
public class BloggingMongoModelBuilderConfigurationOptions : MongoModelBuilderConfigurationOptions |
||||
|
{ |
||||
|
public BloggingMongoModelBuilderConfigurationOptions([NotNull] string tablePrefix = BloggingConsts.DefaultDbTablePrefix) |
||||
|
: base(tablePrefix) |
||||
|
{ |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,27 @@ |
|||||
|
using MongoDB.Driver; |
||||
|
using Volo.Abp.Data; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Blogging.Blogs; |
||||
|
using Volo.Blogging.Comments; |
||||
|
using Volo.Blogging.Posts; |
||||
|
using Volo.Blogging.Users; |
||||
|
|
||||
|
namespace Volo.Blogging.MongoDB |
||||
|
{ |
||||
|
[ConnectionStringName("Blogging")] |
||||
|
public interface IBloggingMongoDbContext : IAbpMongoDbContext |
||||
|
{ |
||||
|
IMongoCollection<BlogUser> Users { get; } |
||||
|
|
||||
|
IMongoCollection<Blog> Blogs { get; } |
||||
|
|
||||
|
IMongoCollection<Post> Posts { get; } |
||||
|
|
||||
|
IMongoCollection<Tagging.Tag> Tags { get; } |
||||
|
|
||||
|
IMongoCollection<PostTag> PostTags { get; } |
||||
|
|
||||
|
IMongoCollection<Comment> Comments { get; } |
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Entities; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Blogging.MongoDB; |
||||
|
|
||||
|
namespace Volo.Blogging.Posts |
||||
|
{ |
||||
|
public class MongoPostRepository : MongoDbRepository<IBloggingMongoDbContext, Post, Guid>, IPostRepository |
||||
|
{ |
||||
|
public MongoPostRepository(IMongoDbContextProvider<IBloggingMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<List<Post>> GetPostsByBlogId(Guid id) |
||||
|
{ |
||||
|
return await GetMongoQueryable().Where(p => p.BlogId == id).OrderByDescending(p => p.CreationTime).ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
public async Task<Post> GetPostByUrl(Guid blogId, string url) |
||||
|
{ |
||||
|
var post = await GetMongoQueryable().FirstOrDefaultAsync(p => p.BlogId == blogId && p.Url == url); |
||||
|
|
||||
|
if (post == null) |
||||
|
{ |
||||
|
throw new EntityNotFoundException(typeof(Post), nameof(post)); |
||||
|
} |
||||
|
|
||||
|
return post; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
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); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,50 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Blogging.MongoDB; |
||||
|
|
||||
|
namespace Volo.Blogging.Tagging |
||||
|
{ |
||||
|
public class MongoTagRepository : MongoDbRepository<IBloggingMongoDbContext, Tag, Guid>, ITagRepository |
||||
|
{ |
||||
|
public MongoTagRepository(IMongoDbContextProvider<IBloggingMongoDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<List<Tag>> GetListAsync(Guid blogId) |
||||
|
{ |
||||
|
return await GetMongoQueryable().Where(t=>t.BlogId == blogId).ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
public async Task<Tag> GetByNameAsync(Guid blogId, string name) |
||||
|
{ |
||||
|
return await GetMongoQueryable().Where(t => t.BlogId == blogId && t.Name == name).FirstAsync(); |
||||
|
} |
||||
|
|
||||
|
public async Task<Tag> FindByNameAsync(Guid blogId, string name) |
||||
|
{ |
||||
|
return await GetMongoQueryable().Where(t => t.BlogId == blogId && t.Name == name).FirstOrDefaultAsync(); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<Tag>> GetListAsync(IEnumerable<Guid> ids) |
||||
|
{ |
||||
|
return await GetMongoQueryable().Where(t => ids.Contains(t.Id)).ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
public void DecreaseUsageCountOfTags(List<Guid> ids) |
||||
|
{ |
||||
|
var tags = GetMongoQueryable().Where(t => ids.Contains(t.Id)); |
||||
|
|
||||
|
foreach (var tag in tags) |
||||
|
{ |
||||
|
tag.DecreaseUsageCount(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,30 @@ |
|||||
|
using System.Collections.Generic; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.Users.MongoDB; |
||||
|
using Volo.Blogging.MongoDB; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
|
||||
|
namespace Volo.Blogging.Users |
||||
|
{ |
||||
|
public class MongoBlogUserRepository : MongoUserRepositoryBase<IBloggingMongoDbContext, BlogUser>, IBlogUserRepository |
||||
|
{ |
||||
|
public MongoBlogUserRepository(IMongoDbContextProvider<IBloggingMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<List<BlogUser>> GetUsersAsync(int maxCount, string filter, CancellationToken cancellationToken) |
||||
|
{ |
||||
|
var query = GetMongoQueryable(); |
||||
|
|
||||
|
if (!string.IsNullOrWhiteSpace(filter)) |
||||
|
{ |
||||
|
query = query.Where(x => x.UserName.Contains(filter)); |
||||
|
} |
||||
|
|
||||
|
return await query.Take(maxCount).ToListAsync(cancellationToken); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue