내 지난 얘측 보기 기능 추가, 한국 멕시코 경기 응원가 1곡 추가
This commit is contained in:
1 parent
0e5a63a28b
commit
b4fc96f299
12 files changed
+257
-8
No files matched your search
+26
-1
@@ -11,12 +11,14 @@ from __future__ import annotations
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
from .config import settings
|
||||
from .models import AIPrediction, CrowdStats, Match
|
||||
from .models import AIPrediction, CrowdStats, Match, UserPrediction
|
||||
from .schemas import (
|
||||
AIPredictionOut,
|
||||
CrowdStatsOut,
|
||||
MatchOut,
|
||||
MatchResult,
|
||||
MyPredictionOut,
|
||||
MyResultOut,
|
||||
Team,
|
||||
)
|
||||
|
||||
@@ -116,6 +118,29 @@ def crowd_out(c: CrowdStats | None, match_id: str) -> CrowdStatsOut:
|
||||
)
|
||||
|
||||
|
||||
def my_prediction_out(p: UserPrediction, m: Match) -> MyPredictionOut:
|
||||
"""유저 픽 1건을 경기 정보와 합쳐 직렬화 (내 지난 예측 목록용)."""
|
||||
result = None
|
||||
if m.result_outcome is not None:
|
||||
result = MyResultOut(
|
||||
scoreA=m.result_score_a or 0,
|
||||
scoreB=m.result_score_b or 0,
|
||||
outcome=m.result_outcome, # type: ignore[arg-type]
|
||||
hitOutcome=p.outcome == m.result_outcome,
|
||||
)
|
||||
return MyPredictionOut(
|
||||
matchId=p.match_id,
|
||||
teamA=_team_a(m),
|
||||
teamB=_team_b(m),
|
||||
kickoffKst=kst_iso(m.kickoff_at),
|
||||
outcome=p.outcome, # type: ignore[arg-type]
|
||||
scoreA=p.score_a,
|
||||
scoreB=p.score_b,
|
||||
submittedAt=kst_iso(p.updated_at or p.created_at),
|
||||
result=result,
|
||||
)
|
||||
|
||||
|
||||
def match_out(
|
||||
m: Match,
|
||||
lang: str = "ko",
|
||||
|
||||
@@ -7,10 +7,16 @@ from sqlalchemy.ext.asyncio import AsyncSession
|
||||
from sqlalchemy.orm import selectinload
|
||||
|
||||
from ..database import get_db
|
||||
from ..domain import compute_phase, crowd_out, is_open_for_voting, is_votable
|
||||
from ..domain import (
|
||||
compute_phase,
|
||||
crowd_out,
|
||||
is_open_for_voting,
|
||||
is_votable,
|
||||
my_prediction_out,
|
||||
)
|
||||
from ..models import AIPrediction, CrowdStats, Match, UserPrediction
|
||||
from ..scoring import outcome_of
|
||||
from ..schemas import SubmitPredictionIn, SubmitPredictionOut
|
||||
from ..schemas import MyPredictionOut, SubmitPredictionIn, SubmitPredictionOut
|
||||
|
||||
router = APIRouter(prefix="/api/predictions", tags=["predictions"])
|
||||
|
||||
@@ -36,6 +42,25 @@ async def _adjust_crowd(
|
||||
)
|
||||
|
||||
|
||||
@router.get("/mine", response_model=list[MyPredictionOut])
|
||||
async def my_predictions(
|
||||
email: str, db: AsyncSession = Depends(get_db)
|
||||
) -> list[MyPredictionOut]:
|
||||
"""이메일 기준 내 지난 예측 목록 (최신 제출순). 로그인 없음 — 이메일이 신원."""
|
||||
e = email.strip().lower()
|
||||
if not e:
|
||||
return []
|
||||
rows = (
|
||||
await db.execute(
|
||||
select(UserPrediction, Match)
|
||||
.join(Match, Match.match_id == UserPrediction.match_id)
|
||||
.where(func.lower(UserPrediction.email) == e)
|
||||
.order_by(UserPrediction.updated_at.desc())
|
||||
)
|
||||
).all()
|
||||
return [my_prediction_out(up, m) for up, m in rows]
|
||||
|
||||
|
||||
@router.post("", response_model=SubmitPredictionOut)
|
||||
async def submit_prediction(
|
||||
body: SubmitPredictionIn, db: AsyncSession = Depends(get_db)
|
||||
|
||||
@@ -90,6 +90,26 @@ class SubmitPredictionOut(BaseModel):
|
||||
crowd: CrowdStatsOut
|
||||
|
||||
|
||||
# ── 내 지난 예측 (이메일 기준, 로그인 없음) ──────────────────
|
||||
class MyResultOut(BaseModel):
|
||||
scoreA: int
|
||||
scoreB: int
|
||||
outcome: Outcome
|
||||
hitOutcome: bool # 내 outcome 이 실제 결과와 일치했는지
|
||||
|
||||
|
||||
class MyPredictionOut(BaseModel):
|
||||
matchId: str
|
||||
teamA: Team
|
||||
teamB: Team
|
||||
kickoffKst: str
|
||||
outcome: Outcome
|
||||
scoreA: int
|
||||
scoreB: int
|
||||
submittedAt: str # ISO — 최신순 정렬 기준(updated_at)
|
||||
result: MyResultOut | None = None # 경기 종료 시에만 채워짐
|
||||
|
||||
|
||||
# ── 리더보드 ────────────────────────────────────────────────
|
||||
class StandingOut(BaseModel):
|
||||
rank: int
|
||||
|
||||
Reference in new issue
Block a user