# -*- coding: utf-8 -*- from fastapi import Path, Depends from sqlalchemy.ext.asyncio import AsyncSession from common.const import OBJECTIVE_QUESTION_TYPES from crud.paper import crud_question from models.paper import PaperQuestion from models.user import Teacher from utils.depends import get_async_db, get_current_user async def get_paper_questions(page: int = 1, size: int = 10, pid: int = Path(..., description="试卷ID"), db: AsyncSession = Depends(get_async_db), current_user: Teacher = Depends(get_current_user)): # 分页 offset = (page - 1) * size total, db_questions = await crud_question.find_all( db, filters=[PaperQuestion.pid == pid, PaperQuestion.qtype.notin_(OBJECTIVE_QUESTION_TYPES)], offset=offset, limit=size) return {"data": db_questions, "total": total} # 查看答案 async def get_question_answer(pid: int = Path(..., description="试卷ID"), qno: int = Path(..., description="题号"), sqno: int = Path(..., description="子题号"), db: AsyncSession = Depends(get_async_db), current_user: Teacher = Depends(get_current_user)): db_obj = await crud_question.find_one(db, filters={"pid": pid, "qno": qno, "sqno": sqno}) if not db_obj: return {"errcode": 404, "mess": "试题不存在!"} return {"data": db_obj}