39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
// =====================================================
|
|
// 前台當前競賽 API
|
|
// =====================================================
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { CompetitionService } from '@/lib/services/database-service';
|
|
|
|
// 獲取當前競賽(前台用)
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const currentCompetition = await CompetitionService.getCurrentCompetition();
|
|
|
|
if (!currentCompetition) {
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: '暫無當前競賽',
|
|
data: null
|
|
});
|
|
}
|
|
|
|
// 獲取競賽詳細信息
|
|
const competitionWithDetails = await CompetitionService.getCompetitionWithDetails(currentCompetition.id);
|
|
|
|
return NextResponse.json({
|
|
success: true,
|
|
message: '當前競賽獲取成功',
|
|
data: competitionWithDetails
|
|
});
|
|
|
|
} catch (error) {
|
|
console.error('獲取當前競賽失敗:', error);
|
|
return NextResponse.json({
|
|
success: false,
|
|
message: '獲取當前競賽失敗',
|
|
error: error instanceof Error ? error.message : '未知錯誤'
|
|
}, { status: 500 });
|
|
}
|
|
}
|