Skip to content
Snippets Groups Projects
Commit c22f641a authored by Václav Bílý's avatar Václav Bílý :cowboy:
Browse files

Added events to Commands

parent 02d9ef10
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@
using MediatR;
using SocialNetwork.Social.Application.Common.Interfaces;
using SocialNetwork.Social.Domain.Entities.Feed;
using SocialNetwork.Social.Domain.Events.Feed;
namespace SocialNetwork.Social.Application.Posts.Commands;
......@@ -21,11 +22,10 @@ public class CommentPostCommandHandler(IApplicationDbContext dbContext) : IReque
post.Comments.Add(comment);
await dbContext.SaveChangesAsync(cancellationToken);
post.AddDomainEvent(new PostCommentedEvent(post, comment));
dbContext.Posts.Update(post);
await dbContext.SaveChangesAsync(cancellationToken);
// TODO fire post commented event
return comment;
}
}
......
......@@ -2,6 +2,7 @@
using MediatR;
using SocialNetwork.Social.Application.Common.Interfaces;
using SocialNetwork.Social.Domain.Entities.Feed;
using SocialNetwork.Social.Domain.Events.Feed;
namespace SocialNetwork.Social.Application.Posts.Commands;
......@@ -13,10 +14,11 @@ public class PublishPostCommandHandler(IApplicationDbContext dbContext) : IReque
{
var post = new Post {AuthorId = request.AuthorId, Title = request.Title, Content = request.Content};
post.AddDomainEvent(new PostPublishedEvent(post));
await dbContext.Posts.AddAsync(post, cancellationToken);
await dbContext.SaveChangesAsync(cancellationToken);
// TODO fire event PostPublished
await dbContext.SaveChangesAsync(cancellationToken);
return post;
}
......
using ErrorOr;
using MediatR;
using SocialNetwork.Social.Application.Common.Interfaces;
using SocialNetwork.Social.Domain.Events.Feed;
namespace SocialNetwork.Social.Application.Posts.Commands;
......@@ -16,7 +17,7 @@ public class LikePostCommandHandler(IApplicationDbContext dbContext) : IRequestH
post.LikesCount++; // I would create a whole table for likers and postId to add who liked the post
// TODO fire post liked event
post.AddDomainEvent(new PostLikedEvent(post.Id, request.LikerId));
await dbContext.SaveChangesAsync(cancellationToken);
return Result.Success;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment