// ===================================================== // 競賽統計 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' || c.status === 'ongoing').length, ongoing: competitions.filter(c => c.status === 'ongoing').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 }); } }