Files
ai-showcase-platform/app/api/competitions/[id]/judges/route.ts

72 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// =====================================================
// 競賽評審團 API
// =====================================================
import { NextRequest, NextResponse } from 'next/server';
import { CompetitionService } from '@/lib/services/database-service';
// 獲取競賽的評審團
export async function GET(request: NextRequest, { params }: { params: { id: string } }) {
try {
const { id } = await params;
console.log('🔍 獲取競賽評審團 API 被調用競賽ID:', id);
// 獲取競賽信息
const competition = await CompetitionService.getCompetitionWithDetails(id);
if (!competition) {
console.log('❌ 競賽不存在:', id);
return NextResponse.json({
success: false,
message: '競賽不存在',
error: '找不到指定的競賽'
}, { status: 404 });
}
console.log('✅ 找到競賽:', competition.name);
// 獲取競賽的評審團
const judges = await CompetitionService.getCompetitionJudges(id);
console.log('📊 查詢到評審數量:', judges.length);
console.log('👥 評審詳細資料:', judges);
const response = NextResponse.json({
success: true,
message: '競賽評審團獲取成功',
data: {
competition: {
id: competition.id,
name: competition.name,
type: competition.type
},
judges: judges.map(judge => ({
id: judge.id,
name: judge.name,
title: judge.title,
department: judge.department,
expertise: judge.expertise || [],
avatar: judge.avatar || null,
email: judge.email,
phone: judge.phone,
assignedAt: judge.assigned_at ? new Date(judge.assigned_at).toLocaleDateString('zh-TW') : null
})),
total: judges.length
}
});
// 設置快取控制標頭,防止快取
response.headers.set('Cache-Control', 'no-cache, no-store, must-revalidate');
response.headers.set('Pragma', 'no-cache');
response.headers.set('Expires', '0');
return response;
} catch (error) {
console.error('❌ 獲取競賽評審團失敗:', error);
return NextResponse.json({
success: false,
message: '獲取競賽評審團失敗',
error: error instanceof Error ? error.message : '未知錯誤'
}, { status: 500 });
}
}