some changes

This commit is contained in:
john 2025-05-17 23:47:19 +02:00
parent 4ec9720541
commit b47bac67ca
37 changed files with 397 additions and 190 deletions

View file

@ -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
}

View 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);
}
}