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