|
| 1 | +import { |
| 2 | + Controller, |
| 3 | + Get, |
| 4 | + Param, |
| 5 | + Query, |
| 6 | + Logger, |
| 7 | +} from '@nestjs/common'; |
| 8 | +import { SkillRatingService } from '../skill-rating.service'; |
| 9 | +import { PlayerRating } from '../entities/player-rating.entity'; |
| 10 | +import { PlayerRatingDetails } from '../skill-rating.service'; |
| 11 | + |
| 12 | +/** |
| 13 | + * GET /players/me/rating — authenticated player's rating, tier, and percentile |
| 14 | + * GET /players/:id/rating — another player's rating (respects privacy settings) |
| 15 | + */ |
| 16 | +@Controller('players') |
| 17 | +export class PlayerRatingController { |
| 18 | + private readonly logger = new Logger(PlayerRatingController.name); |
| 19 | + |
| 20 | + constructor(private readonly skillRatingService: SkillRatingService) {} |
| 21 | + |
| 22 | + @Get('me/rating') |
| 23 | + async getMyRating( |
| 24 | + @Query('userId') userId: string, |
| 25 | + ): Promise<PlayerRatingDetails> { |
| 26 | + return this.skillRatingService.getPlayerRatingWithDetails(userId); |
| 27 | + } |
| 28 | + |
| 29 | + @Get(':id/rating') |
| 30 | + async getPlayerRating( |
| 31 | + @Param('id') targetUserId: string, |
| 32 | + @Query('requestingUserId') requestingUserId?: string, |
| 33 | + ): Promise<PlayerRatingDetails> { |
| 34 | + return this.skillRatingService.getPublicPlayerRating(targetUserId, requestingUserId); |
| 35 | + } |
| 36 | +} |
| 37 | + |
| 38 | +/** |
| 39 | + * GET /ratings/leaderboard — top 100 players by skill rating, |
| 40 | + * kept separate from the score-based leaderboard. |
| 41 | + */ |
| 42 | +@Controller('ratings') |
| 43 | +export class RatingsController { |
| 44 | + constructor(private readonly skillRatingService: SkillRatingService) {} |
| 45 | + |
| 46 | + @Get('leaderboard') |
| 47 | + async getLeaderboard( |
| 48 | + @Query('limit') limit = '100', |
| 49 | + @Query('offset') offset = '0', |
| 50 | + ): Promise<PlayerRating[]> { |
| 51 | + return this.skillRatingService.getLeaderboard( |
| 52 | + parseInt(limit, 10), |
| 53 | + parseInt(offset, 10), |
| 54 | + ); |
| 55 | + } |
| 56 | +} |
0 commit comments