實現得獎資訊與資料庫整合
This commit is contained in:
@@ -98,6 +98,7 @@ export async function POST(request: NextRequest) {
|
||||
// 獲取獎項列表
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
console.log('🔍 開始獲取獎項列表...');
|
||||
const { searchParams } = new URL(request.url);
|
||||
const competitionId = searchParams.get('competitionId');
|
||||
const awardType = searchParams.get('awardType');
|
||||
@@ -105,14 +106,20 @@ export async function GET(request: NextRequest) {
|
||||
const year = searchParams.get('year');
|
||||
const month = searchParams.get('month');
|
||||
|
||||
console.log('📋 查詢參數:', { competitionId, awardType, category, year, month });
|
||||
|
||||
let awards;
|
||||
|
||||
if (competitionId) {
|
||||
console.log('🎯 根據競賽ID獲取獎項:', competitionId);
|
||||
awards = await AwardService.getAwardsByCompetition(competitionId);
|
||||
} else {
|
||||
console.log('📊 獲取所有獎項');
|
||||
awards = await AwardService.getAllAwards();
|
||||
}
|
||||
|
||||
console.log('✅ 獲取到獎項數量:', awards?.length || 0);
|
||||
|
||||
// 應用篩選條件
|
||||
if (awardType) {
|
||||
awards = awards.filter(award => award.award_type === awardType);
|
||||
@@ -127,10 +134,27 @@ export async function GET(request: NextRequest) {
|
||||
awards = awards.filter(award => award.month === parseInt(month));
|
||||
}
|
||||
|
||||
// 解析 JSON 欄位
|
||||
const processedAwards = awards.map(award => {
|
||||
console.log('🔍 處理獎項:', {
|
||||
id: award.id,
|
||||
competition_name: (award as any).competition_name,
|
||||
competition_type: (award as any).competition_type,
|
||||
competition_id: award.competition_id
|
||||
});
|
||||
|
||||
return {
|
||||
...award,
|
||||
application_links: award.application_links ? JSON.parse(award.application_links) : null,
|
||||
documents: award.documents ? JSON.parse(award.documents) : [],
|
||||
photos: award.photos ? JSON.parse(award.photos) : [],
|
||||
};
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
message: '獎項列表獲取成功',
|
||||
data: awards
|
||||
data: processedAwards
|
||||
});
|
||||
|
||||
} catch (error) {
|
||||
@@ -141,4 +165,4 @@ export async function GET(request: NextRequest) {
|
||||
error: error instanceof Error ? error.message : '未知錯誤'
|
||||
}, { status: 500 });
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user