后端:添加添加好友处理事件
文档:添加测试环境文档
This commit is contained in:
@@ -175,5 +175,28 @@ namespace IM_API.Services
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 创建好友关系
|
||||
public async Task MakeFriendshipAsync(int userAId, int userBId, string? remarkName)
|
||||
{
|
||||
bool userAexist = await _context.Friends.AnyAsync(x => x.UserId == userAId && x.FriendId == userBId);
|
||||
if (!userAexist)
|
||||
{
|
||||
User? userbInfo = await _context.Users.FirstOrDefaultAsync(x => x.Id == userBId);
|
||||
if (userbInfo is null) throw new BaseException(CodeDefine.USER_NOT_FOUND);
|
||||
Friend friendA = new Friend()
|
||||
{
|
||||
Avatar = userbInfo.Avatar,
|
||||
Created = DateTime.UtcNow,
|
||||
FriendId = userbInfo.Id,
|
||||
RemarkName = remarkName ?? userbInfo.NickName,
|
||||
StatusEnum = FriendStatus.Added,
|
||||
UserId = userAId
|
||||
};
|
||||
_context.Friends.Add(friendA);
|
||||
await _context.SaveChangesAsync();
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user