#!/usr/bin/env python # -*- coding: utf-8 -*- from fastapi import Query, Depends from sqlalchemy.ext.asyncio import AsyncSession from crud.user import crud_student from models.user import Teacher from utils.depends import get_async_db, get_current_user # 学生列表 async def get_students(page: int = 1, size: int = 10, cid: int = Query(..., description="班级ID"), sno: str = Query("", description="学号"), name: str = Query("", description="学生姓名"), db: AsyncSession = Depends(get_async_db), current_user: Teacher = Depends(get_current_user)): # 过滤条件 filters = {"class_id": cid} if sno: filters["sno"] = sno if name: filters["name"] = name offset = (page - 1) * size return_fields = ["id", "name", "sno", "class_id", "class_name"] total, items = await crud_student.find_all(db, filters=filters, offset=offset, limit=size, return_fields=return_fields) return {"total": total, "data": items}