teacher.py 670 B

12345678910111213141516171819202122
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. from fastapi import Depends
  4. from sqlalchemy import text
  5. from sqlalchemy.ext.asyncio import AsyncSession
  6. from crud.school import crud_class
  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=[text("id IN (%s)" % current_user.class_id)],
  15. return_fields=return_fields)
  16. return {"data": items, "total": total}