using System.Threading;
using Dpz.Core.Public.ViewModel.RequestEvent;
namespace Dpz.Core.Service.Event;
public class AddCommentCountEvent(IRepository<Video> repository, ICommentService service)
: IRequestHandler<AddCommentCountRequest>
{
public async Task Handle(AddCommentCountRequest request, CancellationToken cancellationToken)
{
if (request.CommentType != CommentNode.Video)
{
return;
}
var count = await service.GetCommentCountAsync(request.CommentType, request.Relation);
var update = Builders<Video>.Update.Set(x => x.CommentCount, count + 1);
await repository.UpdateAsync(x => x.Id == request.Relation, update);
}
}