Refactor: Next.js+Firebase → React(Vite) + FastAPI + PostgreSQL
- 백엔드: FastAPI + SQLAlchemy(async) + PostgreSQL, 별도 워커(APScheduler) - 프론트: React 19 + Vite + TS + Tailwind v4 (기존 UI 이식, API 연동) - docker-compose: db · api · worker · frontend 일괄 실행 - 경기 일정: openfootball 매일 09:00 크롤링 → DB upsert (신규 경기 자동 삽입+예측 생성) - AI 예측: GPT·Claude·Gemini 실 API 매일 생성 → DB 저장 → 조회 (목데이터 제거) - 투표창: 오픈 킥오프 D-2 / 마감 킥오프 1시간 전, lockAt 백엔드 전달→프론트 카운트다운 - 채점/리더보드: docs/SCORING.md 기준 누적 포인트 - crowd: 0 시작, 실제 제출로만 증분 - 구 Next.js/Firebase 파일 제거, README/AGENTS 갱신 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
35414a8d47
commit
6ffe0dfca3
95 files changed
+5266
-8856
No files matched your search
@@ -0,0 +1,72 @@
|
||||
"""관리자 API — Bearer 토큰 인증. 경기/AI예측 upsert + 결과 입력(채점)."""
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, Header, HTTPException
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from ..config import settings
|
||||
from ..database import get_db
|
||||
from ..domain import now_utc
|
||||
from ..models import AIPrediction, Match
|
||||
from ..schemas import AdminAIPredictionIn, AdminSetResultIn, GenericOk
|
||||
from ..services.grading import apply_result
|
||||
|
||||
router = APIRouter(prefix="/api/admin", tags=["admin"])
|
||||
|
||||
|
||||
def require_admin(authorization: str = Header(default="")) -> None:
|
||||
token = authorization.removeprefix("Bearer ").strip()
|
||||
if not token or token != settings.admin_api_token:
|
||||
raise HTTPException(status_code=401, detail="UNAUTHORIZED")
|
||||
|
||||
|
||||
@router.post("/ai-predictions", response_model=GenericOk, dependencies=[Depends(require_admin)])
|
||||
async def upsert_ai_prediction(
|
||||
body: AdminAIPredictionIn, db: AsyncSession = Depends(get_db)
|
||||
) -> GenericOk:
|
||||
match = (
|
||||
await db.execute(select(Match).where(Match.match_id == body.matchId))
|
||||
).scalars().first()
|
||||
if not match:
|
||||
raise HTTPException(status_code=404, detail="MATCH_NOT_FOUND")
|
||||
|
||||
pred = (
|
||||
await db.execute(
|
||||
select(AIPrediction).where(
|
||||
AIPrediction.match_id == body.matchId, AIPrediction.model == body.model
|
||||
)
|
||||
)
|
||||
).scalars().first()
|
||||
if pred is None:
|
||||
pred = AIPrediction(match_id=body.matchId, model=body.model)
|
||||
db.add(pred)
|
||||
pred.outcome = body.outcome
|
||||
pred.score_a = body.scoreA
|
||||
pred.score_b = body.scoreB
|
||||
pred.confidence_pct = body.confidencePct
|
||||
pred.reason_ko = body.reasonKo
|
||||
pred.reason_en = body.reasonEn
|
||||
pred.generated_at = now_utc()
|
||||
pred.source = "admin"
|
||||
await db.commit()
|
||||
return GenericOk(ok=True, detail="upserted")
|
||||
|
||||
|
||||
@router.post("/result", response_model=GenericOk, dependencies=[Depends(require_admin)])
|
||||
async def set_result(
|
||||
body: AdminSetResultIn, db: AsyncSession = Depends(get_db)
|
||||
) -> GenericOk:
|
||||
match = (
|
||||
await db.execute(select(Match).where(Match.match_id == body.matchId))
|
||||
).scalars().first()
|
||||
if not match:
|
||||
raise HTTPException(status_code=404, detail="MATCH_NOT_FOUND")
|
||||
|
||||
graded = await apply_result(db, match, body.scoreA, body.scoreB)
|
||||
# 결과 메일은 워커가 result_email_delay_minutes 경과 후 발송(@finished_at 기준).
|
||||
return GenericOk(
|
||||
ok=True,
|
||||
detail="result set & graded",
|
||||
extra={"gradedPicks": graded, "emailsSentBy": "worker"},
|
||||
)
|
||||
Reference in new issue
Block a user