Files
IM_NEW/ContactService.WebApi/Application/EventHandler/UserProfileUpdateHandler.cs
T
2026-04-30 21:08:28 +08:00

36 lines
1.1 KiB
C#

using ContactService.Domain;
using ContactService.Infrastructure;
using IM.Commons.IntegrationEvents;
using MassTransit;
namespace ContactService.WebApi.Application.EventHandler
{
public class UserProfileUpdateHandler : IConsumer<UserProfileUpdateEvent>
{
private readonly ContactDbContext contactDb;
private readonly IFriendReposity reposity;
public UserProfileUpdateHandler(ContactDbContext contactDb, IFriendReposity reposity)
{
this.contactDb = contactDb;
this.reposity = reposity;
}
public async Task Consume(ConsumeContext<UserProfileUpdateEvent> context)
{
var @event = context.Message;
var friends = await reposity.FindByTargetAsync(@event.UserId);
foreach (var friend in friends)
{
friend.UpdateUserInfo(
new Domain.ValueObjects.UserProfile(
@event.UserId, @event.Avatar, @event.NickName));
}
await contactDb.SaveChangesAsync();
}
}
}