55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
using ContactService.Domain.Events;
|
|
using ContactService.Domain.ValueObjects;
|
|
using IM.DomainCommons;
|
|
|
|
namespace ContactService.Domain.Entities
|
|
{
|
|
public class Friend : AggregateRootEntity
|
|
{
|
|
public UserProfile Owner { get; private set; }
|
|
public UserProfile Target { get; private set; }
|
|
/// <summary>
|
|
/// 好友备注名
|
|
/// </summary>
|
|
public string? RemarkName { get; private set; }
|
|
public FriendStatus Status { get; private set; }
|
|
|
|
private Friend() { }
|
|
|
|
public Friend(UserProfile owner, UserProfile target, string? remarkName)
|
|
{
|
|
Owner = owner;
|
|
Target = target;
|
|
RemarkName = remarkName;
|
|
Status = FriendStatus.Added;
|
|
|
|
AddDomainEvent(new FriendAddedDomainEvent(this));
|
|
}
|
|
|
|
public void setRemarkName(string? remarkName)
|
|
{
|
|
if (remarkName.Length > 20)
|
|
{
|
|
throw new DomainException("备注名过长");
|
|
}
|
|
RemarkName = remarkName ?? RemarkName;
|
|
}
|
|
|
|
public void Block()
|
|
{
|
|
Status = FriendStatus.Blocked;
|
|
AddDomainEvent(new FriendBlockDomainEvent(this));
|
|
}
|
|
|
|
public void UpdateUserInfo(UserProfile profile)
|
|
{
|
|
if (profile.Id != Target.Id)
|
|
{
|
|
return;
|
|
}
|
|
|
|
Target = profile;
|
|
}
|
|
}
|
|
}
|