teacher.py 690 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from fastapi import Depends
  4. from sqlalchemy.ext.asyncio import AsyncSession
  5. from crud.school import crud_class
  6. from models.school import SchoolClass
  7. from models.user import Teacher
  8. from utils.depends import get_async_db, get_current_user
  9. async def get_classes(db: AsyncSession = Depends(get_async_db),
  10. current_user: Teacher = Depends(get_current_user)):
  11. return_fields = ["id", "name", "student_amount"]
  12. total, items = await crud_class.find_all(
  13. db,
  14. filters=[SchoolClass.id.in_(current_user.class_id.split(","))],
  15. return_fields=return_fields)
  16. return {"data": items, "total": total}