question.py 827 B

1234567891011121314151617181920212223242526
  1. # -*- coding: utf-8 -*-
  2. from fastapi import Path, Depends
  3. from sqlalchemy.ext.asyncio import AsyncSession
  4. from crud.paper import crud_question
  5. from models.user import Teacher
  6. from utils.depends import get_async_db, get_current_user
  7. async def get_paper_questions(
  8. page: int = 1,
  9. size: int = 10,
  10. pid: int = Path(..., description="试卷ID"),
  11. db: AsyncSession = Depends(get_async_db),
  12. current_user: Teacher = Depends(get_current_user)):
  13. # 分页
  14. offset = (page - 1) * size
  15. total, db_questions = await crud_question.find_all(db,
  16. filters={"pid": pid},
  17. offset=offset,
  18. limit=size)
  19. return {"data": db_questions, "total": total}