预测历史:比赛信息内嵌到预测API + 实际比分自动填充
后端: - PredictionOut 新增 match 字段(内嵌比赛信息) - list_predictions 返回完整比赛数据(日期/队名/赛果/主客徽标) - 新增 _match_dict() 辅助函数序列化比赛对象 前端: - 移除独立的 fetchMatches 调用,直接使用 p.match - 实际比分自动从比赛赛果填充 - 显示:比赛日(M/D) + 主客队徽标 + 队伍中文名 - 赛后一键结算(使用比赛实际赛果) Co-Authored-By: new-provider/LongCat-2.0 <<EMAIL>> )
This commit is contained in:
@@ -167,11 +167,31 @@ async def list_predictions(
|
||||
actual_home_goals=p.actual_home_goals,
|
||||
actual_away_goals=p.actual_away_goals,
|
||||
settled=p.settled,
|
||||
match=_match_dict(p.match) if p.match else None,
|
||||
)
|
||||
for p in rows
|
||||
]
|
||||
|
||||
|
||||
def _match_dict(m) -> dict | None:
|
||||
if m is None:
|
||||
return None
|
||||
return {
|
||||
"id": m.id,
|
||||
"league_code": m.league.code if m.league else None,
|
||||
"season": m.season,
|
||||
"home_team": m.home_team.name if m.home_team else "?",
|
||||
"away_team": m.away_team.name if m.away_team else "?",
|
||||
"home_team_zh": m.home_team.name_zh if m.home_team else None,
|
||||
"away_team_zh": m.away_team.name_zh if m.away_team else None,
|
||||
"match_date": m.match_date.isoformat() if m.match_date else None,
|
||||
"match_status": m.match_status,
|
||||
"home_goals": m.home_goals,
|
||||
"away_goals": m.away_goals,
|
||||
"match_stage": m.match_stage,
|
||||
}
|
||||
|
||||
|
||||
@router.get("/predictions/{prediction_id}", response_model=PredictionOut, dependencies=[Depends(require_admin)])
|
||||
async def get_prediction(prediction_id: int, db: AsyncSession = Depends(get_db_read)):
|
||||
p = await db.get(Prediction, prediction_id)
|
||||
|
||||
Reference in New Issue
Block a user