mirror of https://github.com/abpframework/abp.git
7 changed files with 178 additions and 9 deletions
@ -0,0 +1,55 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using MongoDB.Driver; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.CmsKit.Comments; |
||||
|
|
||||
|
namespace Volo.CmsKit.MongoDB.Comments |
||||
|
{ |
||||
|
public class MongoCommentRepository : MongoDbRepository<ICmsKitMongoDbContext, Comment, Guid>, ICommentRepository |
||||
|
{ |
||||
|
public MongoCommentRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<List<CommentWithAuthor>> GetListWithAuthorsAsync( |
||||
|
string entityType, |
||||
|
string entityId) |
||||
|
{ |
||||
|
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); |
||||
|
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); |
||||
|
|
||||
|
var query = from comment in GetMongoQueryable() |
||||
|
join user in DbContext.CmsUsers on comment.CreatorId equals user.Id |
||||
|
where entityType == comment.EntityType && entityId == comment.EntityId |
||||
|
orderby comment.CreationTime |
||||
|
select new CommentWithAuthor |
||||
|
{ |
||||
|
Comment = comment, |
||||
|
Author = user |
||||
|
}; |
||||
|
|
||||
|
return await query.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
public override async Task DeleteAsync(Guid id, bool autoSave = false, CancellationToken cancellationToken = default) |
||||
|
{ |
||||
|
var replies = await GetMongoQueryable() |
||||
|
.Where(x => x.RepliedCommentId == id) |
||||
|
.ToListAsync(GetCancellationToken(cancellationToken)); |
||||
|
|
||||
|
foreach (var reply in replies) |
||||
|
{ |
||||
|
//TODO: Discuss if it is better to mark it as deleted and show in the ui as "This is deleted" instead of deleting it and replies completely
|
||||
|
await base.DeleteAsync(reply.Id, autoSave, GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
|
||||
|
await base.DeleteAsync(id, autoSave, GetCancellationToken(cancellationToken)); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -1,13 +1,19 @@ |
|||||
using Volo.Abp.Data; |
using MongoDB.Driver; |
||||
|
using Volo.Abp.Data; |
||||
using Volo.Abp.MongoDB; |
using Volo.Abp.MongoDB; |
||||
|
using Volo.CmsKit.Comments; |
||||
|
using Volo.CmsKit.Reactions; |
||||
|
using Volo.CmsKit.Users; |
||||
|
|
||||
namespace Volo.CmsKit.MongoDB |
namespace Volo.CmsKit.MongoDB |
||||
{ |
{ |
||||
[ConnectionStringName(CmsKitDbProperties.ConnectionStringName)] |
[ConnectionStringName(CmsKitDbProperties.ConnectionStringName)] |
||||
public interface ICmsKitMongoDbContext : IAbpMongoDbContext |
public interface ICmsKitMongoDbContext : IAbpMongoDbContext |
||||
{ |
{ |
||||
/* Define mongo collections here. Example: |
IMongoCollection<UserReaction> UserReactions { get; } |
||||
* IMongoCollection<Question> Questions { get; } |
|
||||
*/ |
IMongoCollection<Comment> Comments { get; } |
||||
|
|
||||
|
IMongoCollection<CmsUser> CmsUsers { get; } |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,75 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using MongoDB.Driver; |
||||
|
using MongoDB.Driver.Linq; |
||||
|
using Volo.Abp; |
||||
|
using Volo.Abp.Domain.Repositories.MongoDB; |
||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.CmsKit.Reactions; |
||||
|
|
||||
|
namespace Volo.CmsKit.MongoDB.Reactions |
||||
|
{ |
||||
|
public class MongoUserReactionRepository : MongoDbRepository<ICmsKitMongoDbContext, UserReaction, Guid>, IUserReactionRepository |
||||
|
{ |
||||
|
public MongoUserReactionRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) : base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
public async Task<UserReaction> FindAsync( |
||||
|
Guid userId, |
||||
|
string entityType, |
||||
|
string entityId, |
||||
|
string reactionName) |
||||
|
{ |
||||
|
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); |
||||
|
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); |
||||
|
Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName)); |
||||
|
|
||||
|
return await GetMongoQueryable() |
||||
|
.Where(x => |
||||
|
x.CreatorId == userId && |
||||
|
x.EntityType == entityType && |
||||
|
x.EntityId == entityId && |
||||
|
x.ReactionName == reactionName) |
||||
|
.FirstOrDefaultAsync(); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<UserReaction>> GetListForUserAsync( |
||||
|
Guid userId, |
||||
|
string entityType, |
||||
|
string entityId) |
||||
|
{ |
||||
|
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); |
||||
|
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); |
||||
|
|
||||
|
return await GetMongoQueryable() |
||||
|
.Where(x => |
||||
|
x.CreatorId == userId && |
||||
|
x.EntityType == entityType && |
||||
|
x.EntityId == entityId) |
||||
|
.ToListAsync(); |
||||
|
} |
||||
|
|
||||
|
public async Task<List<ReactionSummaryQueryResultItem>> GetSummariesAsync( |
||||
|
string entityType, |
||||
|
string entityId) |
||||
|
{ |
||||
|
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); |
||||
|
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); |
||||
|
|
||||
|
return await GetMongoQueryable() |
||||
|
.Where(x => |
||||
|
x.EntityType == entityType && |
||||
|
x.EntityId == entityId) |
||||
|
.GroupBy(x => x.ReactionName) |
||||
|
.Select(g => new ReactionSummaryQueryResultItem |
||||
|
{ |
||||
|
ReactionName = g.Key, |
||||
|
Count = g.Count() |
||||
|
}) |
||||
|
.ToListAsync(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,15 @@ |
|||||
|
using Volo.Abp.MongoDB; |
||||
|
using Volo.Abp.Users.MongoDB; |
||||
|
using Volo.CmsKit.Users; |
||||
|
|
||||
|
namespace Volo.CmsKit.MongoDB.Users |
||||
|
{ |
||||
|
public class MongoCmsUserRepository : MongoUserRepositoryBase<ICmsKitMongoDbContext, CmsUser>, ICmsUserRepository |
||||
|
{ |
||||
|
public MongoCmsUserRepository(IMongoDbContextProvider<ICmsKitMongoDbContext> dbContextProvider) |
||||
|
: base(dbContextProvider) |
||||
|
{ |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue