forked from xiangwang25/whale-town-end-v2
Initial WhaleTown V2 backend
This commit is contained in:
61
src/business/rankings/rankings.controller.ts
Normal file
61
src/business/rankings/rankings.controller.ts
Normal file
@@ -0,0 +1,61 @@
|
||||
import { Controller, Get, Query } from '@nestjs/common';
|
||||
import { ApiOperation, ApiQuery, ApiTags } from '@nestjs/swagger';
|
||||
import { RankingsService } from './rankings.service';
|
||||
import { RankingCategoryId } from './rankings.types';
|
||||
|
||||
@ApiTags('rankings')
|
||||
@Controller('rankings')
|
||||
export class RankingsController {
|
||||
constructor(private readonly rankingsService: RankingsService) {}
|
||||
|
||||
@Get('datawhale-honor')
|
||||
@ApiOperation({
|
||||
summary: '获取Datawhale荣誉榜',
|
||||
description: '返回后端同步并计算后的Datawhale贡献者排行榜数据,供游戏荣誉榜UI使用。',
|
||||
})
|
||||
@ApiQuery({
|
||||
name: 'category',
|
||||
required: false,
|
||||
description: '榜单分类:weekly_commits/night_owl/popularity/productive/social/rising/comprehensive',
|
||||
})
|
||||
@ApiQuery({
|
||||
name: 'limit',
|
||||
required: false,
|
||||
description: '返回数量,范围 3-10,默认 10',
|
||||
})
|
||||
@ApiQuery({
|
||||
name: 'refresh',
|
||||
required: false,
|
||||
description: '为 true 时先实时同步 Datawhale 公开数据,再返回当前榜单',
|
||||
})
|
||||
async getDatawhaleHonorRanking(
|
||||
@Query('category') category?: RankingCategoryId,
|
||||
@Query('limit') limit?: string,
|
||||
@Query('refresh') refresh?: string,
|
||||
) {
|
||||
const data = await this.rankingsService.getDatawhaleHonorRanking(
|
||||
category,
|
||||
Number(limit || 10),
|
||||
refresh === 'true',
|
||||
);
|
||||
return {
|
||||
success: true,
|
||||
data,
|
||||
message: '荣誉榜获取成功',
|
||||
};
|
||||
}
|
||||
|
||||
@Get('datawhale-honor/sync')
|
||||
@ApiOperation({
|
||||
summary: '手动同步Datawhale荣誉榜',
|
||||
description: '开发调试用:立即从Datawhale公开数据源同步并返回默认榜单。',
|
||||
})
|
||||
async syncDatawhaleHonorRanking() {
|
||||
const data = await this.rankingsService.syncNow();
|
||||
return {
|
||||
success: true,
|
||||
data,
|
||||
message: '荣誉榜同步成功',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user