新增 競賽建立、評審建立、團隊建立
This commit is contained in:
45
app/api/admin/competitions/stats/route.ts
Normal file
45
app/api/admin/competitions/stats/route.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
// =====================================================
|
||||
// 競賽統計 API
|
||||
// =====================================================
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { CompetitionService } from '@/lib/services/database-service';
|
||||
|
||||
// 獲取競賽統計數據
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const competitions = await CompetitionService.getAllCompetitions();
|
||||
|
||||
// 計算統計數據
|
||||
const stats = {
|
||||
total: competitions.length,
|
||||
upcoming: competitions.filter(c => c.status === 'upcoming').length,
|
||||
active: competitions.filter(c => c.status === 'active').length,
|
||||
judging: competitions.filter(c => c.status === 'judging').length,
|
||||
completed: competitions.filter(c => c.status === 'completed').length,
|
||||
individual: competitions.filter(c => c.type === 'individual').length,
|
||||
team: competitions.filter(c => c.type === 'team').length,
|
||||
mixed: competitions.filter(c => c.type === 'mixed').length,
|
||||
proposal: competitions.filter(c => c.type === 'proposal').length,
|
||||
currentYear: competitions.filter(c => c.year === new Date().getFullYear()).length,
|
||||
thisMonth: competitions.filter(c =>
|
||||
c.year === new Date().getFullYear() &&
|
||||
c.month === new Date().getMonth() + 1
|
||||
).length
|
||||
};
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '競賽統計獲取成功',
|
||||
data: stats
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
console.error('獲取競賽統計失敗:', error);
|
||||
return NextResponse.json({
|
||||
success: false,
|
||||
message: '獲取競賽統計失敗',
|
||||
error: error instanceof Error ? error.message : '未知錯誤'
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user