Merge branch 'master' of https://gitea.nxsir.cn/nanxun/IM_NEW
This commit is contained in:
@@ -6,23 +6,26 @@ namespace ContactService.WebApi.Application.Dtos
|
||||
{
|
||||
public Guid Id { get; private set; }
|
||||
/// <summary>
|
||||
/// 申请人
|
||||
/// 申请人
|
||||
/// </summary>
|
||||
public Guid OwnerId { get; private set; }
|
||||
public string? OwnerNickName { get; set; }
|
||||
public string? OwnerAvatar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 被申请人
|
||||
/// 被申请人
|
||||
/// </summary>
|
||||
public Guid TargetId { get; private set; }
|
||||
|
||||
public string? TargetNickName { get; set; }
|
||||
public string? TargetAvatar { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 申请附言
|
||||
/// 申请附言
|
||||
/// </summary>
|
||||
public string Description { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 申请状态(0:待通过,1:拒绝,2:同意,3:拉黑)
|
||||
/// 申请状态(0:待通过,1:拒绝,2:同意,3:拉黑)
|
||||
/// </summary>
|
||||
public FriendRequestStatus State { get; private set; }
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using AutoMapper;
|
||||
using ContactService.Domain;
|
||||
using ContactService.WebApi.Application.Dtos;
|
||||
using ContactService.WebApi.Application.IntegrationServices;
|
||||
using IM.Commons;
|
||||
|
||||
namespace ContactService.WebApi.Application.FriendRequest
|
||||
@@ -10,12 +11,15 @@ namespace ContactService.WebApi.Application.FriendRequest
|
||||
private readonly IFriendRequestReposity reposity;
|
||||
private readonly FriendRequestDomainService service;
|
||||
private readonly IMapper mapper;
|
||||
private readonly IIdentityIntegrationService identityService;
|
||||
|
||||
public FriendRequestService(IFriendRequestReposity reposity, FriendRequestDomainService service, IMapper mapper)
|
||||
public FriendRequestService(IFriendRequestReposity reposity, FriendRequestDomainService service,
|
||||
IMapper mapper, IIdentityIntegrationService identityService)
|
||||
{
|
||||
this.reposity = reposity;
|
||||
this.service = service;
|
||||
this.mapper = mapper;
|
||||
this.identityService = identityService;
|
||||
}
|
||||
|
||||
public async Task<Result<FriendRequestResponse>> CreateAsync(CreateFriendRequestCommand command)
|
||||
@@ -25,7 +29,9 @@ namespace ContactService.WebApi.Application.FriendRequest
|
||||
{
|
||||
return Result<FriendRequestResponse>.Fail(request);
|
||||
}
|
||||
return Result<FriendRequestResponse>.Success(mapper.Map<FriendRequestResponse>(request.Data));
|
||||
var response = mapper.Map<FriendRequestResponse>(request.Data);
|
||||
await PopulateUserInfoAsync(response);
|
||||
return Result<FriendRequestResponse>.Success(response);
|
||||
}
|
||||
|
||||
public async Task<Result<FriendRequestResponse>> UpdateStatusAsync(FriendRequestHandleCommand command)
|
||||
@@ -55,27 +61,81 @@ namespace ContactService.WebApi.Application.FriendRequest
|
||||
default:
|
||||
return Result<FriendRequestResponse>.Fail(ResultCode.PARAMETER_ERROR);
|
||||
}
|
||||
return Result<FriendRequestResponse>.Success(mapper.Map<FriendRequestResponse>(request));
|
||||
var response = mapper.Map<FriendRequestResponse>(request);
|
||||
await PopulateUserInfoAsync(response);
|
||||
return Result<FriendRequestResponse>.Success(response);
|
||||
}
|
||||
|
||||
public async Task<Result<List<FriendRequestResponse>>> GetByOwnerIdAsync(Guid ownerId)
|
||||
{
|
||||
var requests = await reposity.FindByOwnerIdAsync(ownerId);
|
||||
return Result<List<FriendRequestResponse>>.Success(mapper.Map<List<FriendRequestResponse>>(requests));
|
||||
|
||||
var responses = mapper.Map<List<FriendRequestResponse>>(requests);
|
||||
await PopulateUserInfoAsync(responses);
|
||||
return Result<List<FriendRequestResponse>>.Success(responses);
|
||||
}
|
||||
|
||||
public async Task<Result<List<FriendRequestResponse>>> GetByTargetIdAsync(Guid targetId)
|
||||
{
|
||||
var requests = await reposity.FindByTargetIdAsync(targetId);
|
||||
return Result<List<FriendRequestResponse>>.Success(mapper.Map<List<FriendRequestResponse>>(requests));
|
||||
var responses = mapper.Map<List<FriendRequestResponse>>(requests);
|
||||
await PopulateUserInfoAsync(responses);
|
||||
return Result<List<FriendRequestResponse>>.Success(responses);
|
||||
}
|
||||
|
||||
public async Task<Result<List<FriendRequestResponse>>> GetByTargetIdOrOwnerIdAsync(Guid id)
|
||||
{
|
||||
var requests = await reposity.FindByTargetIdAsync(id);
|
||||
var requests2 = await reposity.FindByOwnerIdAsync(id);
|
||||
return Result<List<FriendRequestResponse>>.Success(mapper.Map<List<FriendRequestResponse>>(requests.Concat(requests2)));
|
||||
var responses = mapper.Map<List<FriendRequestResponse>>(requests.Concat(requests2));
|
||||
await PopulateUserInfoAsync(responses);
|
||||
return Result<List<FriendRequestResponse>>.Success(responses);
|
||||
}
|
||||
|
||||
private async Task PopulateUserInfoAsync(List<FriendRequestResponse> responses)
|
||||
{
|
||||
if (responses.Count == 0) return;
|
||||
|
||||
var allUserIds = responses.Select(r => r.OwnerId)
|
||||
.Concat(responses.Select(r => r.TargetId))
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
var userResult = await identityService.FindByIdsAsync(allUserIds);
|
||||
if (!userResult.Succeeded || userResult.Data == null) return;
|
||||
|
||||
var userDict = userResult.Data;
|
||||
foreach (var r in responses)
|
||||
{
|
||||
if (userDict.TryGetValue(r.OwnerId, out var owner))
|
||||
{
|
||||
r.OwnerNickName = owner.NickName;
|
||||
r.OwnerAvatar = owner.Avatar;
|
||||
}
|
||||
if (userDict.TryGetValue(r.TargetId, out var target))
|
||||
{
|
||||
r.TargetNickName = target.NickName;
|
||||
r.TargetAvatar = target.Avatar;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async Task PopulateUserInfoAsync(FriendRequestResponse response)
|
||||
{
|
||||
var ids = new List<Guid> { response.OwnerId, response.TargetId }.Distinct().ToList();
|
||||
var userResult = await identityService.FindByIdsAsync(ids);
|
||||
if (!userResult.Succeeded || userResult.Data == null) return;
|
||||
|
||||
var userDict = userResult.Data;
|
||||
if (userDict.TryGetValue(response.OwnerId, out var owner))
|
||||
{
|
||||
response.OwnerNickName = owner.NickName;
|
||||
response.OwnerAvatar = owner.Avatar;
|
||||
}
|
||||
if (userDict.TryGetValue(response.TargetId, out var target))
|
||||
{
|
||||
response.TargetNickName = target.NickName;
|
||||
response.TargetAvatar = target.Avatar;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,5 +6,6 @@ namespace ContactService.WebApi.Application.IntegrationServices
|
||||
public interface IIdentityIntegrationService
|
||||
{
|
||||
Task<Result<UserInfoDto>> FindUserByIdAsync(Guid id);
|
||||
Task<Result<Dictionary<Guid, UserInfoDto>>> FindByIdsAsync(List<Guid> ids);
|
||||
}
|
||||
}
|
||||
|
||||
+34
-2
@@ -27,7 +27,7 @@ namespace ContactService.WebApi.Application.IntegrationServices
|
||||
{
|
||||
Avatar = res.Avatar,
|
||||
CreationTime = res.CreationTime.ToDateTimeOffset(),
|
||||
Deletion = res.Deletion.ToDateTimeOffset(),
|
||||
Deletion = res.Deletion != null ? res.Deletion.ToDateTimeOffset() : null,
|
||||
Description = res.Description,
|
||||
Email = res.Email,
|
||||
Id = Guid.Parse(res.Id),
|
||||
@@ -40,8 +40,40 @@ namespace ContactService.WebApi.Application.IntegrationServices
|
||||
{
|
||||
return Result.Fail<UserInfoDto>(ResultCode.USER_NOT_FOUND);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public async Task<Result<Dictionary<Guid, UserInfoDto>>> FindByIdsAsync(List<Guid> ids)
|
||||
{
|
||||
if (ids == null || ids.Count == 0)
|
||||
return Result.Success(new Dictionary<Guid, UserInfoDto>());
|
||||
|
||||
var req = new GetUserListRequest();
|
||||
req.UserIds.AddRange(ids.Select(x => x.ToString()));
|
||||
|
||||
try
|
||||
{
|
||||
var res = await client.GetUserListAsyncAsync(req);
|
||||
var dict = res.Users.ToDictionary(
|
||||
u => Guid.Parse(u.Id),
|
||||
u => new UserInfoDto
|
||||
{
|
||||
Id = Guid.Parse(u.Id),
|
||||
UserName = u.UserName,
|
||||
NickName = u.NickName,
|
||||
Email = u.Email,
|
||||
Phone = u.Phone,
|
||||
Region = u.Region,
|
||||
Description = u.Description,
|
||||
Avatar = u.Avatar,
|
||||
CreationTime = u.CreationTime.ToDateTimeOffset(),
|
||||
Deletion = u.Deletion != null ? u.Deletion.ToDateTimeOffset() : null
|
||||
});
|
||||
return Result.Success(dict);
|
||||
}
|
||||
catch (RpcException)
|
||||
{
|
||||
return Result.Fail<Dictionary<Guid, UserInfoDto>>(ResultCode.USER_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,13 @@
|
||||
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||
WORKDIR /src
|
||||
|
||||
COPY IM_API_NEW.sln ./
|
||||
|
||||
COPY ContactService.WebApi/ContactService.WebApi.csproj ContactService.WebApi/
|
||||
COPY ContactService.Domain/ContactService.Domain.csproj ContactService.Domain/
|
||||
COPY ContactService.Infrastructure/ContactService.Infrastructure.csproj ContactService.Infrastructure/
|
||||
COPY DomainCommons/IM.DomainCommons.csproj DomainCommons/
|
||||
COPY Infrastructure/IM.Infrastructure.csproj Infrastructure/
|
||||
COPY IM.ASPNETCore/IM.ASPNETCore.csproj IM.ASPNETCore/
|
||||
COPY IM.Commons/IM.Commons.csproj IM.Commons/
|
||||
COPY IM.InitCommon/IM.InitCommon.csproj IM.InitCommon/
|
||||
COPY IM.Jwt/IM.Jwt.csproj IM.Jwt/
|
||||
COPY IM.Protocols/IM.Protocols.csproj IM.Protocols/
|
||||
|
||||
RUN dotnet restore ContactService.WebApi/ContactService.WebApi.csproj
|
||||
|
||||
COPY . .
|
||||
|
||||
RUN find . -type d \( -name obj -o -name bin \) -prune -exec rm -rf {} + 2>/dev/null || true
|
||||
|
||||
RUN dotnet publish ContactService.WebApi/ContactService.WebApi.csproj \
|
||||
-c Release \
|
||||
-o /app/publish \
|
||||
--no-restore
|
||||
-o /app/publish
|
||||
|
||||
FROM swr.cn-north-4.myhuaweicloud.com/ddn-k8s/mcr.microsoft.com/dotnet/aspnet:8.0 AS runtime
|
||||
WORKDIR /app
|
||||
|
||||
Reference in New Issue
Block a user