完成評審評分機制

This commit is contained in:
2025-09-18 18:34:31 +08:00
parent 2101767690
commit ffa1e45f63
54 changed files with 5730 additions and 709 deletions

View File

@@ -0,0 +1,30 @@
// =====================================================
// 競賽規則 API
// =====================================================
import { NextRequest, NextResponse } from 'next/server';
import { ScoringService } from '@/lib/services/database-service';
// 獲取競賽的評分規則
export async function GET(request: NextRequest, { params }: { params: { id: string } }) {
try {
const { id } = await params;
// 獲取競賽規則
const rules = await ScoringService.getCompetitionRules(id);
return NextResponse.json({
success: true,
message: '競賽規則獲取成功',
data: rules
});
} catch (error) {
console.error('獲取競賽規則失敗:', error);
return NextResponse.json({
success: false,
message: '獲取競賽規則失敗',
error: error instanceof Error ? error.message : '未知錯誤'
}, { status: 500 });
}
}

View File

@@ -143,7 +143,7 @@ export async function GET(request: NextRequest, { params }: { params: { id: stri
return {
...team,
members: allMembers,
apps: teamApps.map(app => app.id),
apps: appsWithDetails, // 返回完整的APP對象而不是ID
appsDetails: appsWithDetails
};
} catch (error) {
@@ -175,22 +175,16 @@ export async function GET(request: NextRequest, { params }: { params: { id: stri
let totalLikes = 0;
// 獲取每個應用的真實數據
for (const appId of team.apps) {
for (const app of team.apps) {
try {
const appSql = 'SELECT likes_count, views_count FROM apps WHERE id = ? AND is_active = TRUE';
const appResult = await db.query(appSql, [appId]);
const likes = app.likes_count || 0;
const views = app.views_count || 0;
if (appResult.length > 0) {
const app = appResult[0];
const likes = app.likes_count || 0;
const views = app.views_count || 0;
maxLikes = Math.max(maxLikes, likes);
totalViews += views;
totalLikes += likes;
}
maxLikes = Math.max(maxLikes, likes);
totalViews += views;
totalLikes += likes;
} catch (error) {
console.error(`獲取應用 ${appId} 數據失敗:`, error);
console.error(`處理應用 ${app.id} 數據失敗:`, error);
}
}
@@ -228,7 +222,21 @@ export async function GET(request: NextRequest, { params }: { params: { id: stri
name: member.name,
role: member.role === '??????' ? '成員' : (member.role || '成員')
})),
apps: team.apps,
apps: team.apps.map(app => ({
id: app.id,
name: app.name,
description: app.description,
category: app.category,
type: app.type,
icon: app.icon,
icon_color: app.icon_color,
likes_count: app.likes_count,
views_count: app.views_count,
rating: app.rating,
creator_name: app.creator_name,
creator_department: app.creator_department,
created_at: app.created_at
})),
appsDetails: team.appsDetails || [],
popularityScore: team.popularityScore,
maxLikes: team.maxLikes,

View File

@@ -0,0 +1,33 @@
import { NextRequest, NextResponse } from 'next/server';
import { ScoringService } from '@/lib/services/database-service';
// 獲取競賽評分進度
export async function GET(request: NextRequest) {
try {
const { searchParams } = new URL(request.url);
const competitionId = searchParams.get('competitionId');
if (!competitionId) {
return NextResponse.json({
success: false,
message: '缺少競賽ID參數'
}, { status: 400 });
}
const progress = await ScoringService.getCompetitionScoringProgress(competitionId);
return NextResponse.json({
success: true,
message: '評分進度獲取成功',
data: progress
});
} catch (error) {
console.error('獲取評分進度失敗:', error);
return NextResponse.json({
success: false,
message: '獲取評分進度失敗',
error: error instanceof Error ? error.message : '未知錯誤'
}, { status: 500 });
}
}