pierrejeambrun commented on code in PR #51264:
URL: https://github.com/apache/airflow/pull/51264#discussion_r2121508221
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -54,23 +54,45 @@
from airflow.api_fastapi.core_api.datamodels.dags import (
DAGCollectionResponse,
DAGDetailsResponse,
+ DAGFavoriteBody,
DAGPatchBody,
DAGResponse,
)
from airflow.api_fastapi.core_api.openapi.exceptions import
create_openapi_http_exception_doc
from airflow.api_fastapi.core_api.security import (
EditableDagsFilterDep,
+ GetUserDep,
ReadableDagsFilterDep,
requires_access_dag,
)
from airflow.api_fastapi.logging.decorators import action_logging
from airflow.exceptions import AirflowException, DagNotFound
from airflow.models import DAG, DagModel
+from airflow.models.dag_favorite import DagFavorite
from airflow.models.dagrun import DagRun
dags_router = AirflowRouter(tags=["DAG"], prefix="/dags")
+@dags_router.get("/favorite",
dependencies=[Depends(requires_access_dag(method="GET"))])
Review Comment:
not sure about `dags/favorite` maybe that should be on it's own root patch
`favorites`. (also always plural). Or even better, maybe just a filter option
in the `get_dags` endpoint (probably only the UI one). `favorite: true/false`.
So we can beneficiate from the full features of the get_dags endpoint but also
on favorites. (for instance GET all the favorite dags with a dag_id_pattern
that is .... ordering_by something else)
Maybe that sould be actions on the dag. `dags/{dag_id}/favorite`
`dags/{dag_id}/unfavorite`. (POST on both) So we don't even need a body.
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -54,23 +54,45 @@
from airflow.api_fastapi.core_api.datamodels.dags import (
DAGCollectionResponse,
DAGDetailsResponse,
+ DAGFavoriteBody,
DAGPatchBody,
DAGResponse,
)
from airflow.api_fastapi.core_api.openapi.exceptions import
create_openapi_http_exception_doc
from airflow.api_fastapi.core_api.security import (
EditableDagsFilterDep,
+ GetUserDep,
ReadableDagsFilterDep,
requires_access_dag,
)
from airflow.api_fastapi.logging.decorators import action_logging
from airflow.exceptions import AirflowException, DagNotFound
from airflow.models import DAG, DagModel
+from airflow.models.dag_favorite import DagFavorite
from airflow.models.dagrun import DagRun
dags_router = AirflowRouter(tags=["DAG"], prefix="/dags")
+@dags_router.get("/favorite",
dependencies=[Depends(requires_access_dag(method="GET"))])
+def get_favorite_dags(session: SessionDep, user: GetUserDep) ->
DAGCollectionResponse:
+ """Get DAGs favorited by the user."""
+ user_id = user.get_id()
+
+ favorite_dags_query = (
+ select(DagModel)
+ .join(DagFavorite, DagModel.dag_id == DagFavorite.dag_id)
+ .where(DagFavorite.user_id == user_id)
+ )
+
+ dags = session.scalars(favorite_dags_query).all()
+
+ return DAGCollectionResponse(
+ dags=dags,
+ total_entries=len(dags),
+ )
Review Comment:
I think we are missing filtering the dag_id by the `readable_dag_ids`
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -54,23 +54,45 @@
from airflow.api_fastapi.core_api.datamodels.dags import (
DAGCollectionResponse,
DAGDetailsResponse,
+ DAGFavoriteBody,
DAGPatchBody,
DAGResponse,
)
from airflow.api_fastapi.core_api.openapi.exceptions import
create_openapi_http_exception_doc
from airflow.api_fastapi.core_api.security import (
EditableDagsFilterDep,
+ GetUserDep,
ReadableDagsFilterDep,
requires_access_dag,
)
from airflow.api_fastapi.logging.decorators import action_logging
from airflow.exceptions import AirflowException, DagNotFound
from airflow.models import DAG, DagModel
+from airflow.models.dag_favorite import DagFavorite
from airflow.models.dagrun import DagRun
dags_router = AirflowRouter(tags=["DAG"], prefix="/dags")
+@dags_router.get("/favorite",
dependencies=[Depends(requires_access_dag(method="GET"))])
+def get_favorite_dags(session: SessionDep, user: GetUserDep) ->
DAGCollectionResponse:
+ """Get DAGs favorited by the user."""
Review Comment:
```suggestion
"""Get DAGs favorited by the user."""
```
Reword, `favorited` seems weird
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -346,6 +368,39 @@ def patch_dags(
)
+@dags_router.put(
+ "/{dag_id}",
+ responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
+ dependencies=[Depends(requires_access_dag(method="PUT")),
Depends(action_logging())],
+)
+def favorite_dag(
+ dag_id: str,
+ favorite_body: DAGFavoriteBody,
+ session: SessionDep,
+ user: GetUserDep,
+) -> DAGResponse:
+ """Favorite the specific DAG."""
Review Comment:
```suggestion
"""Mark the DAG as favorite."""
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]