29 lines
882 B
C#
29 lines
882 B
C#
using ContactService.Domain.Entities;
|
|
using ContactService.Domain.ValueObjects;
|
|
using IM.Commons;
|
|
|
|
namespace ContactService.Domain
|
|
{
|
|
public class FriendDomainService
|
|
{
|
|
private readonly IFriendReposity reposity;
|
|
|
|
public FriendDomainService(IFriendReposity reposity)
|
|
{
|
|
this.reposity = reposity;
|
|
}
|
|
|
|
public async Task<Result<Friend?>> CreateAsync(UserProfile owner, UserProfile target, string? remarkName)
|
|
{
|
|
var isExist = await reposity.CheckOwnerIdAndTargetIdAsync(owner.Id, target.Id);
|
|
if (isExist)
|
|
{
|
|
return Result<Friend?>.Fail(ResultCode.ALREADY_FRIENDS);
|
|
}
|
|
var friend = new Friend(owner, target, remarkName);
|
|
var res = await reposity.CreateAsync(friend);
|
|
return Result<Friend?>.Success(res);
|
|
}
|
|
}
|
|
}
|