添加项目文件。
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
using AutoMapper;
|
||||
using ContactService.WebApi.Application.Dtos;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
|
||||
namespace ContactService.WebApi.Application.Friend
|
||||
{
|
||||
public class FriendMapperConfig : Profile
|
||||
{
|
||||
public FriendMapperConfig()
|
||||
{
|
||||
CreateMap<Domain.Entities.Friend, FriendResonse>()
|
||||
.ForMember(dest => dest.Id, opt => opt.MapFrom(src => src.Id))
|
||||
.ForMember(dest => dest.Avatar, opt => opt.MapFrom(src => src.Target.Avatar))
|
||||
.ForMember(dest => dest.Status, opt => opt.MapFrom(src => src.Status))
|
||||
.ForMember(dest => dest.UpdateTime, opt => opt.MapFrom(src => src.ModificationTime.Value.DateTime))
|
||||
.ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.CreationTime.DateTime))
|
||||
.ForMember(dest => dest.NickName, opt => opt.MapFrom(src => src.Target.NickName))
|
||||
.ForMember(dest => dest.RemarkName, opt => opt.MapFrom(src => src.RemarkName))
|
||||
.ForMember(dest => dest.TargetId, opt => opt.MapFrom(src => src.Target.Id))
|
||||
;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user