PNL0 commented on code in PR #51264:
URL: https://github.com/apache/airflow/pull/51264#discussion_r2155473060


##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dags.py:
##########
@@ -346,6 +358,55 @@ def patch_dags(
     )
 
 
+@dags_router.post(
+    "/{dag_id}/favorite",
+    responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
+    dependencies=[Depends(requires_access_dag(method="POST")), 
Depends(action_logging())],
+)
+def favorite_dag(
+    dag_id: str,
+    session: SessionDep,
+    user: GetUserDep,
+) -> DAGResponse:
+    """Mark the DAG as favorite."""
+    dag = session.get(DagModel, dag_id)
+    if not dag:
+        raise HTTPException(status.HTTP_404_NOT_FOUND, detail=f"DAG with id 
'{dag_id}' not found")
+
+    user_id = user.get_id()
+    session.execute(insert(DagFavorite).values(dag_id=dag_id, user_id=user_id))
+    session.commit()
+
+    return DAGResponse.model_validate(dag)
+
+
+@dags_router.post(
+    "/{dag_id}/unfavorite",
+    responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
+    dependencies=[Depends(requires_access_dag(method="POST")), 
Depends(action_logging())],
+)
+def unfavorite_dag(
+    dag_id: str,
+    session: SessionDep,
+    user: GetUserDep,
+) -> DAGResponse:
+    """Unmark the DAG as favorite."""
+    dag = session.get(DagModel, dag_id)
+    if not dag:
+        raise HTTPException(status.HTTP_404_NOT_FOUND, detail=f"DAG with id 
'{dag_id}' not found")
+
+    user_id = user.get_id()
+    session.execute(
+        delete(DagFavorite).where(
+            DagFavorite.dag_id == dag_id,
+            DagFavorite.user_id == user_id,
+        )
+    )
+    session.commit()
+
+    return DAGResponse.model_validate(dag)

Review Comment:
   > We return a dag response, but this does not hold any information about the 
`favorite/non favorite` state of the Dag, not sure if it's relevant.
   
   With the current implementation, I don't think there is the need to return 
specific information, but maybe I'm missing something. 
   What would you suggest? I was thinking that maybe we could just return the 
200 successful code, if no additional information is needed to return. Similar 
to what is done in the delete action, where the 204 code is returned.



-- 
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]

Reply via email to