Files
IM_NEW/GroupService.WebApi/Application/EventHandler/UserProfileUpdateHandler.cs
T
2026-05-09 17:06:30 +08:00

32 lines
973 B
C#

using GroupService.Domain.IReposities;
using GroupService.Infrastructure;
using IM.Commons.IntegrationEvents;
using MassTransit;
namespace GroupService.WebApi.Application.EventHandler
{
public class UserProfileUpdateHandler : IConsumer<UserProfileUpdateEvent>
{
private readonly GroupDbContext db;
private readonly IGroupMemberReposity memberReposity;
public UserProfileUpdateHandler(GroupDbContext db, IGroupMemberReposity memberReposity)
{
this.db = db;
this.memberReposity = memberReposity;
}
public async Task Consume(ConsumeContext<UserProfileUpdateEvent> context)
{
var @event = context.Message;
var members = await memberReposity.FindByUserIdAsync(@event.UserId);
foreach (var member in members)
{
member.UpdateAvatar(@event.Avatar);
}
await db.SaveChangesAsync();
}
}
}