// ===================================================== // 競賽評審關聯管理 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; const judges = await CompetitionService.getCompetitionJudges(id); return NextResponse.json({ success: true, message: '競賽評審列表獲取成功', data: judges }); } catch (error) { console.error('獲取競賽評審失敗:', error); return NextResponse.json({ success: false, message: '獲取競賽評審失敗', error: error instanceof Error ? error.message : '未知錯誤' }, { status: 500 }); } } // 為競賽添加評審 export async function POST(request: NextRequest, { params }: { params: { id: string } }) { try { const { id } = await params; const body = await request.json(); const { judgeIds } = body; if (!judgeIds || !Array.isArray(judgeIds) || judgeIds.length === 0) { return NextResponse.json({ success: false, message: '缺少評審ID列表', error: 'judgeIds 必須是非空陣列' }, { status: 400 }); } const result = await CompetitionService.addCompetitionJudges(id, judgeIds); return NextResponse.json({ success: true, message: '評審添加成功', data: result }); } catch (error) { console.error('添加競賽評審失敗:', error); return NextResponse.json({ success: false, message: '添加競賽評審失敗', error: error instanceof Error ? error.message : '未知錯誤' }, { status: 500 }); } } // 從競賽中移除評審 export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) { try { const { id } = await params; const { searchParams } = new URL(request.url); const judgeId = searchParams.get('judgeId'); if (!judgeId) { return NextResponse.json({ success: false, message: '缺少評審ID', error: 'judgeId 參數是必需的' }, { status: 400 }); } const result = await CompetitionService.removeCompetitionJudge(id, judgeId); return NextResponse.json({ success: true, message: '評審移除成功', data: result }); } catch (error) { console.error('移除競賽評審失敗:', error); return NextResponse.json({ success: false, message: '移除競賽評審失敗', error: error instanceof Error ? error.message : '未知錯誤' }, { status: 500 }); } }