"""题目 API:列表与详情(含选择题、LaTeX 用法解释)。""" from __future__ import annotations from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.orm import Session from app.core.db import get_session from app.repositories.problem_repo import ProblemRepo router = APIRouter(prefix="/problems", tags=["problems"]) @router.get("") async def list_problems(course: str | None = None, session: Session = Depends(get_session)): rows = ProblemRepo(session).list_by_course(course) return [p.to_dict() for p in rows] @router.get("/{pid}") async def get_problem(pid: int, session: Session = Depends(get_session)): row = ProblemRepo(session).get(pid) if not row: raise HTTPException(404, "题目不存在") return row.to_dict()