增加天梯排行榜

This commit is contained in:
yaoyanwei
2025-08-26 14:50:06 +08:00
parent 6fa45b8f74
commit 8be2bf9dec
10 changed files with 491 additions and 8 deletions

View File

@@ -0,0 +1,55 @@
const ladderModel = require('./ladder.model');
const ladderService = require('./ladder.service');
const { UserModel } = require('../users/users.model');
// Get leaderboard
exports.getLeaderboard = async (req, res) => {
try {
const leaderboard = await ladderModel.getLeaderboard();
res.status(200).send(leaderboard);
} catch (error) {
console.error('Error getting leaderboard:', error);
res.status(500).send({ error: 'Failed to get leaderboard' });
}
};
// Get player's position in leaderboard
exports.getPlayerPosition = async (req, res) => {
try {
const { playerId } = req.params;
const position = await ladderModel.getPlayerPosition(playerId);
res.status(200).send({ position });
} catch (error) {
console.error('Error getting player position:', error);
res.status(500).send({ error: 'Failed to get player position' });
}
};
// Get player's rank info
exports.getPlayerRankInfo = async (req, res) => {
try {
const { playerId } = req.params;
const player = await UserModel.getById(playerId);
if (!player) {
return res.status(404).send({ error: 'Player not found' });
}
const rankInfo = ladderService.getPlayerRankInfo(player);
res.status(200).send(rankInfo);
} catch (error) {
console.error('Error getting player rank info:', error);
res.status(500).send({ error: 'Failed to get player rank info' });
}
};
// Get all rank configurations
exports.getRankConfigurations = async (req, res) => {
try {
const configs = ladderService.getAllRankConfigs();
res.status(200).send(configs);
} catch (error) {
console.error('Error getting rank configurations:', error);
res.status(500).send({ error: 'Failed to get rank configurations' });
}
};