some changes
This commit is contained in:
parent
4ec9720541
commit
b47bac67ca
37 changed files with 397 additions and 190 deletions
|
@ -3,9 +3,9 @@ using MediatR;
|
|||
|
||||
namespace Femto.Modules.Blog.Handlers;
|
||||
|
||||
public class PostCreatedIntegrationEventHandler : INotificationHandler<PostCreatedIntegrationEvent>
|
||||
public class PostCreatedIntegrationEventHandler : INotificationHandler<PostCreatedEvent>
|
||||
{
|
||||
public async Task Handle(PostCreatedIntegrationEvent notification, CancellationToken cancellationToken)
|
||||
public async Task Handle(PostCreatedEvent notification, CancellationToken cancellationToken)
|
||||
{
|
||||
// todo
|
||||
}
|
||||
|
|
29
Femto.Modules.Blog/Handlers/UserCreatedEventHandler.cs
Normal file
29
Femto.Modules.Blog/Handlers/UserCreatedEventHandler.cs
Normal file
|
@ -0,0 +1,29 @@
|
|||
using Femto.Modules.Auth.Contracts.Events;
|
||||
using Femto.Modules.Blog.Application;
|
||||
using Femto.Modules.Blog.Domain.Authors;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace Femto.Modules.Blog.Handlers;
|
||||
|
||||
internal class UserCreatedEventHandler(BlogContext context, ILogger<UserCreatedEventHandler> logger) : Common.Integration.EventHandler<UserWasCreatedIntegrationEvent>
|
||||
{
|
||||
protected override async Task Handle(UserWasCreatedIntegrationEvent evt, CancellationToken cancellationToken)
|
||||
{
|
||||
if (await context.Authors.AnyAsync(x => x.Username == evt.Username, cancellationToken))
|
||||
{
|
||||
logger.LogError("can't create author: author with username {Username} already exists", evt.Username);
|
||||
return;
|
||||
}
|
||||
|
||||
if (await context.Authors.AnyAsync(x => x.Id == evt.UserId, cancellationToken))
|
||||
{
|
||||
logger.LogError("can't create author: author with id {UserId} already exists", evt.UserId);
|
||||
return;
|
||||
}
|
||||
|
||||
var author = new Author(evt.UserId, evt.Username);
|
||||
|
||||
await context.Authors.AddAsync(author, cancellationToken);
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue