import { Controller, Get, Query } from '@nestjs/common'; import { ApiBearerAuth, ApiOperation, ApiTags } from '@nestjs/swagger'; import { DataSource } from 'typeorm'; import { ZodValidationPipe } from '../../common/pipes/zod-validation.pipe'; import { ScoreboardService } from './scoreboard.service'; import { EventLogQuerySchema, EventLogRowDto, GraphViewDto, MatrixViewDto, RankingRowDto, } from './dto/scoreboard.dto'; @ApiTags('scoreboard') @ApiBearerAuth() @Controller('api/v1/scoreboard') export class ScoreboardController { constructor( private readonly dataSource: DataSource, private readonly svc: ScoreboardService, ) {} @Get('ranking') @ApiOperation({ summary: 'Authenticated scoreboard ranking (competition ranks)' }) async ranking(): Promise { return this.svc.getRanking(this.dataSource.manager); } @Get('matrix') @ApiOperation({ summary: 'Authenticated scoreboard matrix (players x challenges)' }) async matrix(): Promise { return this.svc.getMatrix(this.dataSource.manager); } @Get('event-log') @ApiOperation({ summary: 'Authenticated recent-solves event log' }) async eventLog( @Query(new ZodValidationPipe(EventLogQuerySchema)) q: { limit?: number }, ): Promise { return this.svc.getEventLog(this.dataSource.manager, q.limit ?? 50); } @Get('graph') @ApiOperation({ summary: 'Authenticated score graph (top 10 players)' }) async graph(): Promise { return this.svc.getGraph(this.dataSource.manager); } }