Files
IM_NEW/GroupService.WebApi/Application/IntegrationServices/IDentityIntegrationService.cs
T

76 lines
2.6 KiB
C#

using GroupService.WebApi.Application.Dtos;
using Grpc.Core;
using IM.Commons;
using IM.Protocols.Grpc.User;
namespace GroupService.WebApi.Application.IntegrationServices
{
public class IDentityIntegrationService : IIdentityIntegrationService
{
private readonly UserInternal.UserInternalClient client;
public IDentityIntegrationService(UserInternal.UserInternalClient client)
{
this.client = client;
}
public async Task<Result<List<UserInfoDto>>> FindByIdsAsync(List<Guid> ids)
{
try
{
var request = new GetUserListRequest();
request.UserIds.AddRange(ids.Select(x => x.ToString()));
var response = await client.GetUserListAsyncAsync(request);
var users = response.Users.Select(x => new UserInfoDto
{
Avatar = x.Avatar,
CreationTime = x.CreationTime.ToDateTimeOffset(),
Deletion = x.Deletion?.ToDateTimeOffset(),
Description = x.Description,
Email = x.Email,
Id = Guid.Parse(x.Id),
NickName = x.NickName,
Phone = x.Phone,
Region = x.Region,
UserName = x.UserName
}).ToList();
return Result.Success(users);
}catch(RpcException e)
{
return Result.Fail<List<UserInfoDto>>(ResultCode.USER_NOT_FOUND);
}
}
public async Task<Result<UserInfoDto>> FindUserByIdAsync(Guid id)
{
try
{
var response = await client.GetUserInfoAsyncAsync(new GetUserInfoRequest()
{
UserId = id.ToString()
});
return Result.Success(new UserInfoDto()
{
Avatar = response.Avatar,
CreationTime = response.CreationTime.ToDateTimeOffset(),
Deletion = response.Deletion.ToDateTimeOffset(),
Description = response.Description,
Email = response.Email,
Id = Guid.Parse(response.Id),
NickName = response.NickName,
Phone = response.Phone,
Region = response.Region,
UserName = response.UserName
});
}catch(RpcException e)
{
return Result.Fail<UserInfoDto>(ResultCode.USER_NOT_FOUND);
}
}
}
}