|
21 | 21 | from sqlalchemy.orm import Session |
22 | 22 | from typing_extensions import Annotated |
23 | 23 |
|
24 | | -from airflow.api_fastapi.common.db.common import get_session |
| 24 | +from airflow.api_fastapi.common.db.common import get_session, paginated_select |
| 25 | +from airflow.api_fastapi.common.parameters import QueryLimit, QueryOffset, SortParam |
25 | 26 | from airflow.api_fastapi.common.router import AirflowRouter |
26 | 27 | from airflow.api_fastapi.core_api.openapi.exceptions import create_openapi_http_exception_doc |
27 | | -from airflow.api_fastapi.core_api.serializers.pools import PoolResponse |
| 28 | +from airflow.api_fastapi.core_api.serializers.pools import PoolCollectionResponse, PoolResponse |
28 | 29 | from airflow.models.pool import Pool |
29 | 30 |
|
30 | 31 | pools_router = AirflowRouter(tags=["Pool"], prefix="/pools") |
@@ -63,3 +64,34 @@ async def get_pool( |
63 | 64 | raise HTTPException(404, f"The Pool with name: `{pool_name}` was not found") |
64 | 65 |
|
65 | 66 | return PoolResponse.model_validate(pool, from_attributes=True) |
| 67 | + |
| 68 | + |
| 69 | +@pools_router.get( |
| 70 | + "/", |
| 71 | + responses=create_openapi_http_exception_doc([401, 403, 404]), |
| 72 | +) |
| 73 | +async def get_pools( |
| 74 | + limit: QueryLimit, |
| 75 | + offset: QueryOffset, |
| 76 | + order_by: Annotated[ |
| 77 | + SortParam, |
| 78 | + Depends(SortParam(["id", "name"], Pool).dynamic_depends()), |
| 79 | + ], |
| 80 | + session: Annotated[Session, Depends(get_session)], |
| 81 | +) -> PoolCollectionResponse: |
| 82 | + """Get all pools entries.""" |
| 83 | + pools_select, total_entries = paginated_select( |
| 84 | + select(Pool), |
| 85 | + [], |
| 86 | + order_by=order_by, |
| 87 | + offset=offset, |
| 88 | + limit=limit, |
| 89 | + session=session, |
| 90 | + ) |
| 91 | + |
| 92 | + pools = session.scalars(pools_select).all() |
| 93 | + |
| 94 | + return PoolCollectionResponse( |
| 95 | + pools=[PoolResponse.model_validate(pool, from_attributes=True) for pool in pools], |
| 96 | + total_entries=total_entries, |
| 97 | + ) |
0 commit comments