mirror of https://github.com/abpframework/abp.git
11 changed files with 267 additions and 19 deletions
@ -0,0 +1,9 @@ |
|||
using Volo.Abp.Domain.Services; |
|||
|
|||
namespace Volo.CmsKit |
|||
{ |
|||
public class CmsKitDomainServiceBase : DomainService |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.CmsKit.Reactions; |
|||
|
|||
namespace Volo.CmsKit |
|||
{ |
|||
public class CmsKitOptions |
|||
{ |
|||
[NotNull] |
|||
public ReactionDefinitionDictionary Reactions { get; } |
|||
|
|||
public CmsKitOptions() |
|||
{ |
|||
Reactions = new ReactionDefinitionDictionary(); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,26 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
using System.Threading.Tasks; |
|||
using Microsoft.Extensions.Options; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class DefaultReactionDefinitionStore : IReactionDefinitionStore, ITransientDependency |
|||
{ |
|||
protected CmsKitOptions Options { get; } |
|||
|
|||
public DefaultReactionDefinitionStore(IOptions<CmsKitOptions> options) |
|||
{ |
|||
Options = options.Value; |
|||
} |
|||
|
|||
public virtual Task<List<ReactionDefinition>> GetAvailableReactionsAsync( |
|||
string entityType, |
|||
Guid? userId) |
|||
{ |
|||
return Task.FromResult(Options.Reactions.Values.ToList()); |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public interface IReactionDefinitionStore |
|||
{ |
|||
Task<List<ReactionDefinition>> GetAvailableReactionsAsync([CanBeNull] string entityType, [CanBeNull] Guid? userId); |
|||
} |
|||
} |
|||
@ -0,0 +1,16 @@ |
|||
using System; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp.Domain.Repositories; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public interface IUserReactionRepository : IBasicRepository<UserReaction, Guid> |
|||
{ |
|||
Task<UserReaction> FindAsync( |
|||
Guid userId, |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId, |
|||
[NotNull] string reactionName); |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class LocalizableIconDictionary : Dictionary<string, string> |
|||
{ |
|||
public string Default { get; set; } |
|||
} |
|||
} |
|||
@ -1,19 +0,0 @@ |
|||
using System; |
|||
using Volo.Abp.Auditing; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class Reaction : Entity<Guid>, IAggregateRoot<Guid>, IHasCreationTime, IMustHaveCreator |
|||
{ |
|||
public string EntityName { get; set; } //TODO: int or create a more common EntityTypes entity/table/...
|
|||
|
|||
public string EntityId { get; set; } |
|||
|
|||
public string ReactionType { get; set; } |
|||
|
|||
public DateTime CreationTime { get; set; } |
|||
|
|||
public Guid CreatorId { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,32 @@ |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Localization; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class ReactionDefinition |
|||
{ |
|||
[NotNull] |
|||
public string Name { get; } |
|||
|
|||
[CanBeNull] |
|||
public ILocalizableString DisplayName { get; set; } |
|||
|
|||
[NotNull] |
|||
public LocalizableIconDictionary Icons { get; } |
|||
|
|||
public ReactionDefinition( |
|||
[NotNull] string name, |
|||
[NotNull] string defaultIcon, |
|||
[CanBeNull] ILocalizableString displayName = null) |
|||
{ |
|||
Name = Check.NotNullOrWhiteSpace(name, nameof(name)); |
|||
DisplayName = displayName; |
|||
|
|||
Icons = new LocalizableIconDictionary |
|||
{ |
|||
Default = Check.NotNullOrWhiteSpace(defaultIcon, nameof(defaultIcon)) |
|||
}; |
|||
} |
|||
} |
|||
} |
|||
@ -0,0 +1,9 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class ReactionDefinitionDictionary : Dictionary<string, ReactionDefinition> |
|||
{ |
|||
|
|||
} |
|||
} |
|||
@ -0,0 +1,97 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Threading.Tasks; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class ReactionManager : CmsKitDomainServiceBase |
|||
{ |
|||
protected IReactionDefinitionStore ReactionDefinitionStore { get; } |
|||
protected IUserReactionRepository UserReactionRepository { get; } |
|||
|
|||
public ReactionManager( |
|||
IUserReactionRepository userReactionRepository, |
|||
IReactionDefinitionStore reactionDefinitionStore) |
|||
{ |
|||
UserReactionRepository = userReactionRepository; |
|||
ReactionDefinitionStore = reactionDefinitionStore; |
|||
} |
|||
|
|||
public virtual async Task<List<ReactionDefinition>> GetAvailableReactionsAsync( |
|||
[CanBeNull] string entityType = null, |
|||
[CanBeNull] Guid? userId = null) |
|||
{ |
|||
return await ReactionDefinitionStore.GetAvailableReactionsAsync(entityType, userId); |
|||
} |
|||
|
|||
public virtual Task<ReactionSummary> GetSummariesAsync( |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId) |
|||
{ |
|||
//TODO: ...
|
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public virtual Task<ReactionDefinition> GetUserReactionsAsync( |
|||
Guid userId, |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId) |
|||
{ |
|||
//TODO: ...
|
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
public virtual async Task<UserReaction> CreateAsync( |
|||
Guid userId, |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId, |
|||
[NotNull] string reactionName) |
|||
{ |
|||
Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); |
|||
Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); |
|||
Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName)); |
|||
|
|||
var existingReaction = await UserReactionRepository.FindAsync(userId, entityType, entityId, reactionName); |
|||
if (existingReaction != null) |
|||
{ |
|||
return existingReaction; |
|||
} |
|||
|
|||
return await UserReactionRepository.InsertAsync( |
|||
new UserReaction( |
|||
GuidGenerator.Create(), |
|||
userId, |
|||
entityType, |
|||
entityId, |
|||
reactionName, |
|||
Clock.Now |
|||
) |
|||
); |
|||
} |
|||
|
|||
public virtual async Task<bool> DeleteAsync( |
|||
Guid userId, |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId, |
|||
[NotNull] string reactionName) |
|||
{ |
|||
var existingReaction = await UserReactionRepository.FindAsync(userId, entityType, entityId, reactionName); |
|||
if (existingReaction == null) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
await UserReactionRepository.DeleteAsync(existingReaction); |
|||
return true; |
|||
} |
|||
} |
|||
|
|||
public class ReactionSummary |
|||
{ |
|||
public ReactionDefinition Reaction { get; set; } |
|||
|
|||
public int Count { get; set; } |
|||
} |
|||
} |
|||
@ -0,0 +1,41 @@ |
|||
using System; |
|||
using JetBrains.Annotations; |
|||
using Volo.Abp; |
|||
using Volo.Abp.Domain.Entities; |
|||
|
|||
namespace Volo.CmsKit.Reactions |
|||
{ |
|||
public class UserReaction : Entity<Guid>, IAggregateRoot<Guid> |
|||
{ |
|||
public virtual string EntityType { get; protected set; } |
|||
|
|||
public virtual string EntityId { get; protected set; } |
|||
|
|||
public virtual string ReactionName { get; protected set; } |
|||
|
|||
public virtual DateTime CreationTime { get; protected set; } |
|||
|
|||
public virtual Guid UserId { get; protected set; } |
|||
|
|||
protected UserReaction() |
|||
{ |
|||
|
|||
} |
|||
|
|||
internal UserReaction( |
|||
Guid id, |
|||
Guid userId, |
|||
[NotNull] string entityType, |
|||
[NotNull] string entityId, |
|||
[NotNull] string reactionName, |
|||
DateTime creationTime) |
|||
: base(id) |
|||
{ |
|||
EntityType = Check.NotNullOrWhiteSpace(entityType, nameof(entityType)); |
|||
EntityId = Check.NotNullOrWhiteSpace(entityId, nameof(entityId)); |
|||
ReactionName = Check.NotNullOrWhiteSpace(reactionName, nameof(reactionName)); |
|||
UserId = userId; |
|||
CreationTime = creationTime; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue