Browse Source

Merge pull request #5947 from abpframework/issue/5463

Publish an event on comment creation for the CMS Kit
pull/5956/head
Halil İbrahim Kalkan 6 years ago
committed by GitHub
parent
commit
72142ec0bb
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo.CmsKit.Public.Application.Contracts.csproj
  2. 4
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/CmsKitPublicApplicationContractsModule.cs
  3. 11
      modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreatedCommentEvent.cs
  4. 16
      modules/cms-kit/src/Volo.CmsKit.Public.Application/Volo/CmsKit/Public/Comments/CommentPublicAppService.cs

1
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo.CmsKit.Public.Application.Contracts.csproj

@ -10,6 +10,7 @@
<ItemGroup>
<ProjectReference Include="..\Volo.CmsKit.Common.Application.Contracts\Volo.CmsKit.Common.Application.Contracts.csproj" />
<ProjectReference Include="..\..\..\..\framework\src\Volo.Abp.EventBus\Volo.Abp.EventBus.csproj" />
</ItemGroup>
</Project>

4
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/CmsKitPublicApplicationContractsModule.cs

@ -1,9 +1,11 @@
using Volo.Abp.Modularity;
using Volo.Abp.EventBus;
namespace Volo.CmsKit.Public
{
[DependsOn(
typeof(CmsKitCommonApplicationContractsModule)
typeof(CmsKitCommonApplicationContractsModule),
typeof(AbpEventBusModule)
)]
public class CmsKitPublicApplicationContractsModule : AbpModule
{

11
modules/cms-kit/src/Volo.CmsKit.Public.Application.Contracts/Volo/CmsKit/Public/Comments/CreatedCommentEvent.cs

@ -0,0 +1,11 @@
using System;
using Volo.Abp.EventBus;
namespace Volo.CmsKit.Public.Comments
{
[EventName("Volo.CmsKit.Comments.Created")]
public class CreatedCommentEvent
{
public Guid Id { get; set; }
}
}

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

@ -7,6 +7,8 @@ using Microsoft.Extensions.Options;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Uow;
using Volo.Abp.Users;
using Volo.CmsKit.Comments;
using Volo.CmsKit.Users;
@ -18,15 +20,21 @@ namespace Volo.CmsKit.Public.Comments
protected CmsKitOptions CmsKitOptions { get; }
protected ICommentRepository CommentRepository { get; }
protected ICmsUserLookupService CmsUserLookupService { get; }
public IDistributedEventBus DistributedEventBus { get; }
public IUnitOfWorkManager UnitOfWorkManager { get; }
public CommentPublicAppService(
ICommentRepository commentRepository,
ICmsUserLookupService cmsUserLookupService,
IDistributedEventBus distributedEventBus,
IUnitOfWorkManager unitOfWorkManager,
IOptions<CmsKitOptions> cmsKitOptions)
{
CmsKitOptions = cmsKitOptions.Value;
CommentRepository = commentRepository;
CmsUserLookupService = cmsUserLookupService;
DistributedEventBus = distributedEventBus;
UnitOfWorkManager = unitOfWorkManager;
}
public virtual async Task<ListResultDto<CommentWithDetailsDto>> GetListAsync(string entityType, string entityId)
@ -56,6 +64,14 @@ namespace Volo.CmsKit.Public.Comments
)
);
await UnitOfWorkManager.Current.SaveChangesAsync();
await DistributedEventBus.PublishAsync(new CreatedCommentEvent
{
Id = comment.Id
});
return ObjectMapper.Map<Comment, CommentDto>(comment);
}

Loading…
Cancel
Save