12345678910111213141516171819202122 |
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- from fastapi import Depends
- from sqlalchemy.ext.asyncio import AsyncSession
- from crud.school import crud_class
- from models.school import SchoolClass
- from models.user import Teacher
- from utils.depends import get_async_db, get_current_user
- async def get_classes(db: AsyncSession = Depends(get_async_db),
- current_user: Teacher = Depends(get_current_user)):
- return_fields = ["id", "name", "student_amount"]
- total, items = await crud_class.find_all(
- db,
- filters=[SchoolClass.id.in_(current_user.class_id.split(","))],
- return_fields=return_fields)
- return {"data": items, "total": total}
|