37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import { Controller, Get, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiResponse } from '@nestjs/swagger';
|
|
import { BalanceQueryService } from '@/application/services/balance-query.service';
|
|
import { QueryBalanceDto, QueryMultiChainBalanceDto } from '../dto/request';
|
|
import { BalanceResponseDto, MultiChainBalanceResponseDto } from '../dto/response';
|
|
import { ChainType } from '@/domain/value-objects';
|
|
|
|
@ApiTags('Balance')
|
|
@Controller('balance')
|
|
export class BalanceController {
|
|
constructor(private readonly balanceService: BalanceQueryService) {}
|
|
|
|
@Get()
|
|
@ApiOperation({ summary: '查询单链余额' })
|
|
@ApiResponse({ status: 200, description: '余额信息', type: BalanceResponseDto })
|
|
async getBalance(@Query() dto: QueryBalanceDto): Promise<BalanceResponseDto> {
|
|
if (!dto.chainType) {
|
|
throw new Error('chainType is required');
|
|
}
|
|
const chainType = ChainType.create(dto.chainType);
|
|
return this.balanceService.getBalance(chainType, dto.address);
|
|
}
|
|
|
|
@Get('multi-chain')
|
|
@ApiOperation({ summary: '查询多链余额' })
|
|
@ApiResponse({ status: 200, description: '多链余额信息', type: MultiChainBalanceResponseDto })
|
|
async getMultiChainBalance(
|
|
@Query() dto: QueryMultiChainBalanceDto,
|
|
): Promise<MultiChainBalanceResponseDto> {
|
|
const balances = await this.balanceService.getBalances(dto.address, dto.chainTypes);
|
|
return {
|
|
address: dto.address,
|
|
balances,
|
|
};
|
|
}
|
|
}
|