Skip to content

Commit

Permalink
Merge branch 'feature/query-userinfo' into feature/2.7.1-union
Browse files Browse the repository at this point in the history
  • Loading branch information
felix-zhaolei committed Dec 18, 2024
2 parents 510d4c1 + a7d4f53 commit 67152b0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using CAServer.CAAccount.Dtos;
using CAServer.Dtos;
Expand All @@ -14,6 +15,8 @@ public interface INickNameAppService
Task<bool> GetPoppedUpAccountAsync();
Task<bool> GetBubblingAccountAsync();
Task ReplaceUserNicknameAsync(ReplaceNicknameDto replaceNicknameDto);

Task<List<CAHolderResultDto>> QueryHolderInfosAsync(List<string> addressList);

DefaultAvatarResponse GetDefaultAvatars();
}
22 changes: 21 additions & 1 deletion src/CAServer.Application/CAAccount/NickNameAppService.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using CAServer.Dtos;
using System.Threading.Tasks;
using AElf.Indexing.Elasticsearch;
Expand All @@ -8,6 +9,7 @@
using CAServer.Common;
using CAServer.Commons;
using CAServer.Contacts;
using CAServer.Contacts.Provider;
using CAServer.Entities.Es;
using CAServer.Etos;
using CAServer.Grains.Grain;
Expand Down Expand Up @@ -38,12 +40,14 @@ public class NickNameAppService : CAServerAppService, INickNameAppService
private readonly INicknameProvider _nicknameProvider;
private readonly IGuardianAppService _guardianAppService;
private readonly IUserProfilePictureProvider _userProfilePictureProvider;
private readonly IContactProvider _contactProvider;

public NickNameAppService(IDistributedEventBus distributedEventBus, IClusterClient clusterClient,
INESTRepository<CAHolderIndex, Guid> holderRepository,
IOptionsSnapshot<HostInfoOptions> hostInfoOptions, IHttpContextAccessor httpContextAccessor,
INicknameProvider nicknameProvider, IGuardianAppService guardianAppService,
IUserProfilePictureProvider userProfilePictureProvider)
IUserProfilePictureProvider userProfilePictureProvider,
IContactProvider contactProvider)
{
_clusterClient = clusterClient;
_distributedEventBus = distributedEventBus;
Expand All @@ -53,6 +57,7 @@ public NickNameAppService(IDistributedEventBus distributedEventBus, IClusterClie
_nicknameProvider = nicknameProvider;
_guardianAppService = guardianAppService;
_userProfilePictureProvider = userProfilePictureProvider;
_contactProvider = contactProvider;
}

public async Task<CAHolderResultDto> SetNicknameAsync(UpdateNickNameDto nickNameDto)
Expand Down Expand Up @@ -181,4 +186,19 @@ public DefaultAvatarResponse GetDefaultAvatars()
DefaultAvatars = _userProfilePictureProvider.GetDefaultUserPictures()
};
}

public async Task<List<CAHolderResultDto>> QueryHolderInfosAsync(List<string> addressList)
{
var guardiansDto = await _contactProvider.GetCaHolderInfoByAddressAsync(addressList, "");
var caHashList = guardiansDto.CaHolderInfo.Select(t => t.CaHash).Distinct().ToList();

var mustQuery = new List<Func<QueryContainerDescriptor<CAHolderIndex>, QueryContainer>>
{
q => q.Terms(i => i.Field(f => f.CaHash).Terms(caHashList))
};
QueryContainer Filter(QueryContainerDescriptor<CAHolderIndex> f) => f.Bool(b => b.Must(mustQuery));

var holders = await _holderRepository.GetListAsync(Filter);
return ObjectMapper.Map<List<CAHolderIndex>, List<CAHolderResultDto>>(holders.Item2);
}
}
8 changes: 8 additions & 0 deletions src/CAServer.HttpApi/Controllers/NickNameController.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using CAServer.CAAccount;
using CAServer.Dtos;
using Microsoft.AspNetCore.Mvc;
Expand Down Expand Up @@ -41,6 +42,13 @@ public async Task<CAHolderResultDto> HolderInfoAsync(HolderInfoDto holderInfo)
return await _nickNameService.UpdateHolderInfoAsync(holderInfo);
}

[HttpGet("queryHolderInfos")]
[AllowAnonymous]
public async Task<List<CAHolderResultDto>> QueryHolderInfosAsync(List<string> addressList)
{
return await _nickNameService.QueryHolderInfosAsync(addressList);
}

[HttpGet("defaultAvatars")]
[AllowAnonymous]
public DefaultAvatarResponse GetDefaultAvatars()
Expand Down

0 comments on commit 67152b0

Please sign in to comment.