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
chaoxkang committed Dec 18, 2024
2 parents 4341607 + 4e9fee4 commit b732ecf
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using CAServer.Dtos;

namespace CAServer.CAAccount.Dtos;

public class CAHolderWithAddressResultDto : CAHolderDto
{
public string CaAddress { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface INickNameAppService
Task<bool> GetBubblingAccountAsync();
Task ReplaceUserNicknameAsync(ReplaceNicknameDto replaceNicknameDto);

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

DefaultAvatarResponse GetDefaultAvatars();
}
26 changes: 19 additions & 7 deletions src/CAServer.Application/CAAccount/NickNameAppService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,18 +187,30 @@ public DefaultAvatarResponse GetDefaultAvatars()
};
}

public async Task<List<CAHolderResultDto>> QueryHolderInfosAsync(List<string> addressList)
public async Task<List<CAHolderWithAddressResultDto>> QueryHolderInfosAsync(List<string> addressList)
{
var result = new List<CAHolderWithAddressResultDto>();
if (addressList.IsNullOrEmpty())
{
return result;
}

var guardiansDto = await _contactProvider.GetCaHolderInfoByAddressAsync(addressList, "");
var caHashList = guardiansDto.CaHolderInfo.Select(t => t.CaHash).Distinct().ToList();
if (caHashList.Count == 0)
{
return result;
}

var mustQuery = new List<Func<QueryContainerDescriptor<CAHolderIndex>, QueryContainer>>
QueryContainer Filter(QueryContainerDescriptor<CAHolderIndex> q) =>
q.Terms(i => i.Field(f => f.CaHash).Terms(caHashList));
var holders = await _holderRepository.GetListAsync(Filter, limit: caHashList.Count, skip: 0);
foreach (var caHolderIndex in holders.Item2)
{
q => q.Terms(i => i.Field(f => f.CaHash).Terms(caHashList))
};
QueryContainer Filter(QueryContainerDescriptor<CAHolderIndex> f) => f.Bool(b => b.Must(mustQuery));
var caHolderWithAddressResultDto = ObjectMapper.Map<CAHolderIndex, CAHolderWithAddressResultDto>(caHolderIndex);
caHolderWithAddressResultDto.CaAddress = guardiansDto.CaHolderInfo.First(t => t.CaHash == caHolderIndex.CaHash).CaAddress;
}

var holders = await _holderRepository.GetListAsync(Filter);
return ObjectMapper.Map<List<CAHolderIndex>, List<CAHolderResultDto>>(holders.Item2);
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,7 @@ public CAServerApplicationAutoMapperProfile()
.ForMember(t => t.Name, f => f.MapFrom(m => m.Name ?? string.Empty))
.ReverseMap();
CreateMap<CAHolderIndex, CAHolderResultDto>();
CreateMap<CAHolderIndex, CAHolderWithAddressResultDto>();
CreateMap<ContactAddress, ContactAddressDto>();
CreateMap<CreateUpdateContactDto, ContactDto>();
CreateMap<ContactDto, ContactGrainDto>();
Expand Down
2 changes: 1 addition & 1 deletion src/CAServer.HttpApi/Controllers/NickNameController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task<CAHolderResultDto> HolderInfoAsync(HolderInfoDto holderInfo)

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

0 comments on commit b732ecf

Please sign in to comment.