添加项目文件。

This commit is contained in:
2026-05-09 17:06:30 +08:00
parent c60f5fe117
commit 720ef957d4
378 changed files with 14843 additions and 0 deletions
@@ -0,0 +1,32 @@
using ContactService.Domain.Events;
using IM.Commons.IntegrationEvents;
using MassTransit;
using MediatR;
namespace ContactService.WebApi.Application.EventHandler
{
public class FriendAddedHandler : INotificationHandler<FriendAddedDomainEvent>
{
private readonly IPublishEndpoint endpoint;
public FriendAddedHandler(IPublishEndpoint endpoint)
{
this.endpoint = endpoint;
}
public async Task Handle(FriendAddedDomainEvent notification, CancellationToken cancellationToken)
{
await endpoint.Publish(new FriendAddedEvent
{
OwnerAvatar = notification.Friend.Owner.Avatar,
OwnerId = notification.Friend.Owner.Id,
OwnerNickName = notification.Friend.Owner.NickName,
TargetAvatar = notification.Friend.Target.Avatar,
TargetId = notification.Friend.Target.Id,
TargetNickName = notification.Friend.Target.NickName,
RemarkName = notification.Friend.RemarkName,
Status = notification.Friend.Status.ToString(),
}, cancellationToken);
}
}
}
@@ -0,0 +1,58 @@
using ContactService.Domain;
using ContactService.Domain.Events;
using ContactService.Domain.ValueObjects;
using ContactService.Infrastructure;
using ContactService.WebApi.Application.IntegrationServices;
using IM.Commons.IntegrationEvents;
using MassTransit;
using MediatR;
namespace ContactService.WebApi.Application.EventHandler
{
public class FriendRequestStatusUpdateHandler : INotificationHandler<FriendRequestStateUpdateDomainEvent>
{
private readonly FriendDomainService friendService;
private readonly ContactDbContext contactDb;
private readonly IPublishEndpoint endpoint;
private readonly IIdentityIntegrationService idService;
public FriendRequestStatusUpdateHandler(FriendDomainService friendService, ContactDbContext contactDb, IPublishEndpoint endpoint, IIdentityIntegrationService idService)
{
this.friendService = friendService;
this.contactDb = contactDb;
this.endpoint = endpoint;
this.idService = idService;
}
public async Task Handle(FriendRequestStateUpdateDomainEvent notification, CancellationToken cancellationToken)
{
var @event = notification.Request;
if (@event.State == FriendRequestStatus.Passed)
{
var ownerInfo = await idService.FindUserByIdAsync(@event.OwnerId);
var targetInfo = await idService.FindUserByIdAsync(@event.TargetId);
if (!ownerInfo.Succeeded || !targetInfo.Succeeded)
{
return;
}
var ownerProfile = new UserProfile(ownerInfo.Data.Id, ownerInfo.Data.NickName, ownerInfo.Data.Avatar);
var targetProfile = new UserProfile(targetInfo.Data.Id, targetInfo.Data.NickName, targetInfo.Data.Avatar);
await friendService.CreateAsync(ownerProfile, targetProfile, @event.RemarkName);
await friendService.CreateAsync(targetProfile, ownerProfile, notification.AcceptRemarkName);
await contactDb.SaveChangesAsync(cancellationToken);
}
await endpoint.Publish(new FriendRequestStateUpdateEvent
{
CorrelationId = @event.TargetId,
Description = @event.Description,
OwnerId = @event.OwnerId,
RemarkName = @event.RemarkName,
State = @event.State.ToString()
});
}
}
}
@@ -0,0 +1,35 @@
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();
}
}
}