Skip to content

Commit

Permalink
feat: add search chain info api
Browse files Browse the repository at this point in the history
  • Loading branch information
becket01 committed Jan 22, 2025
1 parent cc8f7be commit 0085e1a
Showing 9 changed files with 151 additions and 5 deletions.
26 changes: 26 additions & 0 deletions src/EoaServer.Application.Contracts/Search/Dto/ChainsInfoDto.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System;

namespace EoaServer.Search.Dto;

public class ChainsInfoDto
{
public string ChainId { get; set; }
public string ChainName { get; set; }
public string EndPoint { get; set; }
public string ExplorerUrl { get; set; }
public string CaContractAddress { get; set; }
public string DisplayChainName { get; set; }
public string ChainImageUrl { get; set; }
public DefaultTokenInfoDto DefaultToken { get; set; }
public DateTime LastModifyTime { get; set; }
}

public class DefaultTokenInfoDto
{
public string Name { get; set; }
public string Address { get; set; }
public string ImageUrl { get; set; }
public string Symbol { get; set; }
public string Decimals { get; set; }
public long IssueChainId { get; set; }
}
10 changes: 10 additions & 0 deletions src/EoaServer.Application.Contracts/Search/ISearchAppService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Threading.Tasks;
using EoaServer.Search.Dto;
using Volo.Abp.Application.Dtos;

namespace EoaServer.Search;

public interface ISearchAppService
{
Task<PagedResultDto<ChainsInfoDto>> GetChainsInfoAsync();
}
Original file line number Diff line number Diff line change
@@ -6,6 +6,8 @@ namespace EoaServer.UserActivity.Dto;
public class GetActivitiesDto
{
public List<GetActivityDto> Data { get; set; }
public bool HasNextPage { get; set; }
public long TotalRecordCount { get; set; }
}

public class GetActivityDto : ActivityBase
4 changes: 0 additions & 4 deletions src/EoaServer.Application/EoaServer.Application.csproj
Original file line number Diff line number Diff line change
@@ -43,9 +43,5 @@
<HintPath>..\..\..\..\..\..\usr\local\share\dotnet\shared\Microsoft.AspNetCore.App\7.0.0\Microsoft.AspNetCore.SignalR.Core.dll</HintPath>
</Reference>
</ItemGroup>

<ItemGroup>
<Folder Include="User" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
@@ -2,6 +2,7 @@
using EoaServer.Entities.Es;
using EoaServer.Grain.UserToken;
using EoaServer.Options;
using EoaServer.Search.Dto;
using EoaServer.Token.Eto;

namespace EoaServer;
@@ -14,5 +15,7 @@ public EoaServerApplicationAutoMapperProfile()
CreateMap<UserTokenGrainDto, UserTokenEto>().ReverseMap();
CreateMap<UserTokenItem, UserTokenIndex>();
CreateMap<EoaServer.Options.Token, EoaServer.Entities.Es.Token>();
CreateMap<ChainsInfoIndex, ChainsInfoDto>();
CreateMap<DefaultTokenInfo, DefaultTokenInfoDto>();
}
}
49 changes: 49 additions & 0 deletions src/EoaServer.Application/Search/SearchAppService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AElf.Indexing.Elasticsearch;
using EoaServer.Entities.Es;
using EoaServer.Search.Dto;
using Nest;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
using Volo.Abp;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Auditing;
using Volo.Abp.ObjectMapping;

namespace EoaServer.Search;

[RemoteService(false)]
[DisableAuditing]
public class SearchAppService : EoaServerBaseService, ISearchAppService
{
private readonly INESTRepository<ChainsInfoIndex, string> _chainsInfoRepository;
private readonly IObjectMapper _objectMapper;

public SearchAppService(
INESTRepository<ChainsInfoIndex, string> chainsInfoRepository,
IObjectMapper objectMapper)
{
_chainsInfoRepository = chainsInfoRepository;
_objectMapper = objectMapper;
}

public async Task<PagedResultDto<ChainsInfoDto>> GetChainsInfoAsync()
{
var mustQuery = new List<Func<QueryContainerDescriptor<ChainsInfoIndex>, QueryContainer>>();
QueryContainer Filter(QueryContainerDescriptor<ChainsInfoIndex> f) => f.Bool(b => b.Must(mustQuery));

var (totalCount, list) = await _chainsInfoRepository.GetListAsync(Filter);

var serializeSetting = new JsonSerializerSettings
{
ContractResolver = new CamelCasePropertyNamesContractResolver()
};
return new PagedResultDto<ChainsInfoDto>
{
TotalCount = totalCount,
Items = _objectMapper.Map<List<ChainsInfoIndex>, List<ChainsInfoDto>>(list)
};
}
}
Original file line number Diff line number Diff line change
@@ -185,7 +185,10 @@ public async Task<GetActivitiesDto> GetActivitiesAsync(GetActivitiesRequestDto r

return new GetActivitiesDto()
{
Data = activityDtos
Data = activityDtos,
HasNextPage = request.MaxResultCount <= activityDtos.Count,
TotalRecordCount = request.MaxResultCount <= activityDtos.Count
? transactions.Count : request.SkipCount + activityDtos.Count
};
}

28 changes: 28 additions & 0 deletions src/EoaServer.Domain/Entities/Es/ChainsInfoIndex.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System;
using AElf.Indexing.Elasticsearch;
using Nest;

namespace EoaServer.Entities.Es;

public class ChainsInfoIndex : EoaBaseEsEntity<string>, IIndexBuild
{
[Keyword] public string ChainId { get; set; }
[Keyword] public string ChainName { get; set; }
[Keyword] public string EndPoint { get; set; }
[Keyword] public string ExplorerUrl { get; set; }
[Keyword] public string CaContractAddress { get; set; }
[Keyword] public string DisplayChainName { get; set; }
[Keyword] public string ChainImageUrl { get; set; }
public DefaultTokenInfo DefaultToken { get; set; }
public DateTime LastModifyTime { get; set; }
}

public class DefaultTokenInfo
{
[Keyword] public string Name { get; set; }
[Keyword] public string Address { get; set; }
[Keyword] public string ImageUrl { get; set; }
[Keyword] public string Symbol { get; set; }
[Keyword] public string Decimals { get; set; }
public long IssueChainId { get; set; }
}
29 changes: 29 additions & 0 deletions src/EoaServer.HttpApi/Controllers/SearchController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Threading.Tasks;
using Asp.Versioning;
using EoaServer.Search;
using EoaServer.Search.Dto;
using Microsoft.AspNetCore.Mvc;
using Volo.Abp;
using Volo.Abp.Application.Dtos;

namespace EoaServer.Controllers;

[RemoteService]
[Area("app")]
[ControllerName("Search")]
[Route("api/app/search")]
public class SearchController : EoaServerBaseController
{
private readonly ISearchAppService _searchAppService;

public SearchController(ISearchAppService searchAppService)
{
_searchAppService = searchAppService;
}

[HttpGet("chainsinfoindex")]
public async Task<PagedResultDto<ChainsInfoDto>> GetChainsInfoAsync()
{
return await _searchAppService.GetChainsInfoAsync();
}
}

0 comments on commit 0085e1a

Please sign in to comment.