47 lines
1.4 KiB
TypeScript
47 lines
1.4 KiB
TypeScript
import { Controller, Get, Query } from '@nestjs/common';
|
|
import { ApiTags, ApiOperation, ApiQuery, ApiBearerAuth } from '@nestjs/swagger';
|
|
import { PriceService } from '../../application/services/price.service';
|
|
import { Public } from '../../shared/guards/jwt-auth.guard';
|
|
|
|
@ApiTags('Price')
|
|
@Controller('price')
|
|
export class PriceController {
|
|
constructor(private readonly priceService: PriceService) {}
|
|
|
|
@Get('current')
|
|
@Public()
|
|
@ApiOperation({ summary: '获取当前价格信息' })
|
|
async getCurrentPrice() {
|
|
return this.priceService.getCurrentPrice();
|
|
}
|
|
|
|
@Get('latest')
|
|
@Public()
|
|
@ApiOperation({ summary: '获取最新价格快照' })
|
|
async getLatestSnapshot() {
|
|
const snapshot = await this.priceService.getLatestSnapshot();
|
|
if (!snapshot) {
|
|
return { message: 'No price snapshot available' };
|
|
}
|
|
return snapshot;
|
|
}
|
|
|
|
@Get('history')
|
|
@Public()
|
|
@ApiOperation({ summary: '获取价格历史' })
|
|
@ApiQuery({ name: 'startTime', required: true, type: String, description: 'ISO datetime' })
|
|
@ApiQuery({ name: 'endTime', required: true, type: String, description: 'ISO datetime' })
|
|
@ApiQuery({ name: 'limit', required: false, type: Number })
|
|
async getPriceHistory(
|
|
@Query('startTime') startTime: string,
|
|
@Query('endTime') endTime: string,
|
|
@Query('limit') limit?: number,
|
|
) {
|
|
return this.priceService.getPriceHistory(
|
|
new Date(startTime),
|
|
new Date(endTime),
|
|
limit ?? 1440,
|
|
);
|
|
}
|
|
}
|