Browse Source

Refactor the domain layer of the CMS Kit.

pull/5052/head
Halil İbrahim Kalkan 6 years ago
parent
commit
e6a224db73
  1. 7
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs
  2. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/CommentWithAuthorQueryResultItem.cs
  3. 5
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs
  4. 2
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Reactions/DefaultReactionDefinitionStore.cs
  5. 9
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Reactions/IUserReactionRepository.cs
  6. 1
      modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Users/CmsUserLookupService.cs
  7. 4
      modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs
  8. 4
      modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs
  9. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs
  10. 17
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs
  11. 1
      modules/cms-kit/test/Volo.CmsKit.Application.Tests/Reactions/ReactionPublicAppService_Tests.cs

7
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/Comment.cs

@ -44,10 +44,15 @@ namespace Volo.CmsKit.Comments
CreatorId = creatorId; CreatorId = creatorId;
TenantId = tenantId; TenantId = tenantId;
SetText(text); SetTextInternal(text);
} }
public virtual void SetText(string text) public virtual void SetText(string text)
{
SetTextInternal(text);
}
protected virtual void SetTextInternal(string text)
{ {
Text = Check.NotNullOrWhiteSpace(text, nameof(text), CommentConsts.MaxTextLength); Text = Check.NotNullOrWhiteSpace(text, nameof(text), CommentConsts.MaxTextLength);
} }

2
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/CommentWithAuthor.cs → modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/CommentWithAuthorQueryResultItem.cs

@ -2,7 +2,7 @@
namespace Volo.CmsKit.Comments namespace Volo.CmsKit.Comments
{ {
public class CommentWithAuthor public class CommentWithAuthorQueryResultItem
{ {
public Comment Comment { get; set; } public Comment Comment { get; set; }

5
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Comments/ICommentRepository.cs

@ -8,8 +8,9 @@ namespace Volo.CmsKit.Comments
{ {
public interface ICommentRepository : IBasicRepository<Comment, Guid> public interface ICommentRepository : IBasicRepository<Comment, Guid>
{ {
Task<List<CommentWithAuthor>> GetListWithAuthorsAsync( Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
[NotNull] string entityType, [NotNull] string entityType,
[NotNull] string entityId); [NotNull] string entityId
);
} }
} }

2
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Reactions/DefaultReactionDefinitionStore.cs

@ -20,7 +20,7 @@ namespace Volo.CmsKit.Reactions
return Task.FromResult(Options.Reactions.Values.ToList()); return Task.FromResult(Options.Reactions.Values.ToList());
} }
public Task<ReactionDefinition> GetReactionOrNullAsync(string reactionName, string entityType = null) public virtual Task<ReactionDefinition> GetReactionOrNullAsync(string reactionName, string entityType = null)
{ {
return Task.FromResult(Options.Reactions.GetOrDefault(reactionName)); return Task.FromResult(Options.Reactions.GetOrDefault(reactionName));
} }

9
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Reactions/IUserReactionRepository.cs

@ -12,15 +12,18 @@ namespace Volo.CmsKit.Reactions
Guid userId, Guid userId,
[NotNull] string entityType, [NotNull] string entityType,
[NotNull] string entityId, [NotNull] string entityId,
[NotNull] string reactionName); [NotNull] string reactionName
);
Task<List<UserReaction>> GetListForUserAsync( Task<List<UserReaction>> GetListForUserAsync(
Guid userId, Guid userId,
[NotNull] string entityType, [NotNull] string entityType,
[NotNull] string entityId); [NotNull] string entityId
);
Task<List<ReactionSummaryQueryResultItem>> GetSummariesAsync( Task<List<ReactionSummaryQueryResultItem>> GetSummariesAsync(
[NotNull] string entityType, [NotNull] string entityType,
[NotNull] string entityId); [NotNull] string entityId
);
} }
} }

1
modules/cms-kit/src/Volo.CmsKit.Domain/Volo/CmsKit/Users/CmsUserLookupService.cs

@ -19,6 +19,5 @@ namespace Volo.CmsKit.Users
{ {
return new CmsUser(externalUser); return new CmsUser(externalUser);
} }
} }
} }

4
modules/cms-kit/src/Volo.CmsKit.EntityFrameworkCore/Volo/CmsKit/Comments/EfCoreCommentRepository.cs

@ -19,7 +19,7 @@ namespace Volo.CmsKit.Comments
{ {
} }
public async Task<List<CommentWithAuthor>> GetListWithAuthorsAsync( public async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType, string entityType,
string entityId) string entityId)
{ {
@ -30,7 +30,7 @@ namespace Volo.CmsKit.Comments
join user in DbContext.CmsUsers on comment.CreatorId equals user.Id join user in DbContext.CmsUsers on comment.CreatorId equals user.Id
where entityType == comment.EntityType && entityId == comment.EntityId where entityType == comment.EntityType && entityId == comment.EntityId
orderby comment.CreationTime orderby comment.CreationTime
select new CommentWithAuthor select new CommentWithAuthorQueryResultItem
{ {
Comment = comment, Comment = comment,
Author = user Author = user

4
modules/cms-kit/src/Volo.CmsKit.MongoDB/Volo/CmsKit/MongoDB/Comments/MongoCommentRepository.cs

@ -18,7 +18,7 @@ namespace Volo.CmsKit.MongoDB.Comments
{ {
} }
public async Task<List<CommentWithAuthor>> GetListWithAuthorsAsync( public async Task<List<CommentWithAuthorQueryResultItem>> GetListWithAuthorsAsync(
string entityType, string entityType,
string entityId) string entityId)
{ {
@ -40,7 +40,7 @@ namespace Volo.CmsKit.MongoDB.Comments
return comments return comments
.Select( .Select(
comment => comment =>
new CommentWithAuthor new CommentWithAuthorQueryResultItem
{ {
Comment = comment, Comment = comment,
Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId) Author = authors.FirstOrDefault(a => a.Id == comment.CreatorId)

4
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs

@ -93,7 +93,7 @@ namespace Volo.CmsKit.Public.Comments
await CommentRepository.DeleteAsync(id); await CommentRepository.DeleteAsync(id);
} }
private List<CommentWithDetailsDto> ConvertCommentsToNestedStructure(List<CommentWithAuthor> comments) private List<CommentWithDetailsDto> ConvertCommentsToNestedStructure(List<CommentWithAuthorQueryResultItem> comments)
{ {
var parentComments = comments var parentComments = comments
.Where(c=> c.Comment.RepliedCommentId == null) .Where(c=> c.Comment.RepliedCommentId == null)
@ -118,7 +118,7 @@ namespace Volo.CmsKit.Public.Comments
return parentComments; return parentComments;
} }
private CmsUserDto GetAuthorAsDtoFromCommentList(List<CommentWithAuthor> comments, Guid commentId) private CmsUserDto GetAuthorAsDtoFromCommentList(List<CommentWithAuthorQueryResultItem> comments, Guid commentId)
{ {
return ObjectMapper.Map<CmsUser, CmsUserDto>(comments.Single(c => c.Comment.Id == commentId).Author); return ObjectMapper.Map<CmsUser, CmsUserDto>(comments.Single(c => c.Comment.Id == commentId).Author);
} }

17
modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Reactions/ReactionPublicAppService.cs

@ -31,13 +31,14 @@ namespace Volo.CmsKit.Public.Reactions
{ {
var summaries = await ReactionManager.GetSummariesAsync(entityType, entityId); var summaries = await ReactionManager.GetSummariesAsync(entityType, entityId);
var userReactions = CurrentUser.IsAuthenticated ? var userReactionsOrNull = CurrentUser.IsAuthenticated
(await UserReactionRepository ? (await UserReactionRepository
.GetListForUserAsync( .GetListForUserAsync(
CurrentUser.GetId(), CurrentUser.GetId(),
entityType, entityType,
entityId entityId
)).ToDictionary(x => x.ReactionName, x => x) : null; )).ToDictionary(x => x.ReactionName, x => x)
: null;
var reactionWithSelectionDtos = new List<ReactionWithSelectionDto>(); var reactionWithSelectionDtos = new List<ReactionWithSelectionDto>();
@ -48,7 +49,7 @@ namespace Volo.CmsKit.Public.Reactions
{ {
Reaction = ConvertToReactionDto(summary.Reaction), Reaction = ConvertToReactionDto(summary.Reaction),
Count = summary.Count, Count = summary.Count,
IsSelectedByCurrentUser = userReactions?.ContainsKey(summary.Reaction.Name) ?? false IsSelectedByCurrentUser = userReactionsOrNull?.ContainsKey(summary.Reaction.Name) ?? false
} }
); );
} }

1
modules/cms-kit/test/Volo.CmsKit.Application.Tests/Reactions/ReactionPublicAppService_Tests.cs

@ -43,6 +43,7 @@ namespace Volo.CmsKit.Reactions
reactions.Items. reactions.Items.
First(r=>r.Reaction.Name == StandardReactions.Rocket).IsSelectedByCurrentUser.ShouldBeTrue(); First(r=>r.Reaction.Name == StandardReactions.Rocket).IsSelectedByCurrentUser.ShouldBeTrue();
reactions.Items. reactions.Items.
First(r=>r.Reaction.Name == StandardReactions.Rocket).Count.ShouldBe(1); First(r=>r.Reaction.Name == StandardReactions.Rocket).Count.ShouldBe(1);

Loading…
Cancel
Save