74 lines
2.4 KiB
C#
74 lines
2.4 KiB
C#
using AutoMapper;
|
|
using ContactService.Domain;
|
|
using ContactService.WebApi.Application.Dtos;
|
|
using ContactService.WebApi.Application.IntegrationServices;
|
|
using IM.Commons;
|
|
|
|
namespace ContactService.WebApi.Application.Friend
|
|
{
|
|
public class FriendService
|
|
{
|
|
private readonly IFriendReposity reposity;
|
|
private readonly FriendDomainService service;
|
|
private readonly IIdentityIntegrationService idService;
|
|
private readonly IMapper mapper;
|
|
|
|
public FriendService(IFriendReposity reposity, FriendDomainService service
|
|
, IIdentityIntegrationService idService, IMapper mapper
|
|
)
|
|
{
|
|
this.reposity = reposity;
|
|
this.service = service;
|
|
this.idService = idService;
|
|
this.mapper = mapper;
|
|
}
|
|
|
|
public async Task<Result<List<FriendResonse>>> GetFriendsByOwnerIdAsync(Guid ownerId)
|
|
{
|
|
IEnumerable<Domain.Entities.Friend> friend = await reposity.FindByOwnerAsync(ownerId);
|
|
return Result<List<FriendResonse>>.Success(mapper.Map<List<FriendResonse>>(friend.ToList()));
|
|
}
|
|
|
|
public async Task<Result<object>> DeleteFriendAsync(Guid userId, Guid friendId)
|
|
{
|
|
var friend = await reposity.FindByIdAsync(friendId);
|
|
if (friend is null)
|
|
{
|
|
return Result<object>.Fail(ResultCode.FRIEND_RELATION_NOT_FOUND);
|
|
}
|
|
|
|
if (friend.Owner.Id != userId)
|
|
{
|
|
return Result<object>.Fail(ResultCode.FRIEND_RELATION_NOT_FOUND);
|
|
}
|
|
|
|
friend.SoftDelete();
|
|
|
|
return Result<object>.Success();
|
|
}
|
|
|
|
public async Task<Result<object>> BlockFriendAsync(Guid userId, Guid friendId)
|
|
{
|
|
var friend = await reposity.FindByIdAsync(friendId);
|
|
if (friend is null)
|
|
{
|
|
return Result<object>.Fail(ResultCode.FRIEND_RELATION_NOT_FOUND);
|
|
}
|
|
|
|
if (friend.Owner.Id != userId)
|
|
{
|
|
return Result<object>.Fail(ResultCode.PERMISSION_DENIED);
|
|
}
|
|
|
|
friend.Block();
|
|
return Result<object>.Success();
|
|
}
|
|
|
|
public async Task<Result<bool>> CheckFriendAsync(Guid ownerId, Guid targetId)
|
|
{
|
|
var exist = await reposity.CheckOwnerIdAndTargetIdAsync(ownerId, targetId);
|
|
return Result.Success(exist);
|
|
}
|
|
}
|
|
}
|