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>> GetFriendsByOwnerIdAsync(Guid ownerId) { IEnumerable friend = await reposity.FindByOwnerAsync(ownerId); return Result>.Success(mapper.Map>(friend.ToList())); } public async Task> DeleteFriendAsync(Guid userId, Guid friendId) { var friend = await reposity.FindByIdAsync(friendId); if (friend is null) { return Result.Fail(ResultCode.FRIEND_RELATION_NOT_FOUND); } if (friend.Owner.Id != userId) { return Result.Fail(ResultCode.FRIEND_RELATION_NOT_FOUND); } friend.SoftDelete(); return Result.Success(); } public async Task> BlockFriendAsync(Guid userId, Guid friendId) { var friend = await reposity.FindByIdAsync(friendId); if (friend is null) { return Result.Fail(ResultCode.FRIEND_RELATION_NOT_FOUND); } if (friend.Owner.Id != userId) { return Result.Fail(ResultCode.PERMISSION_DENIED); } friend.Block(); return Result.Success(); } public async Task> CheckFriendAsync(Guid ownerId, Guid targetId) { var exist = await reposity.CheckOwnerIdAndTargetIdAsync(ownerId, targetId); return Result.Success(exist); } } }