|
1 | | -from typing import Annotated, Literal |
| 1 | +from typing import Annotated, Any, Literal |
2 | 2 |
|
3 | | -from fastapi import APIRouter, Depends |
| 3 | +from fastapi import APIRouter, Body, Depends |
4 | 4 | from sqlalchemy.ext.asyncio import AsyncConnection |
5 | 5 |
|
6 | 6 | import database.flows |
7 | 7 | from core.conversions import _str_to_num |
8 | 8 | from core.errors import FlowNotFoundError |
9 | | -from routers.dependencies import expdb_connection |
| 9 | +from core.tagging import tag_entity, untag_entity |
| 10 | +from database.users import User |
| 11 | +from routers.dependencies import expdb_connection, fetch_user_or_raise |
| 12 | +from routers.types import SystemString64 |
10 | 13 | from schemas.flows import Flow, Parameter, Subflow |
11 | 14 |
|
12 | 15 | router = APIRouter(prefix="/flows", tags=["flows"]) |
13 | 16 |
|
14 | 17 |
|
| 18 | +@router.post(path="/tag") |
| 19 | +async def tag_flow( |
| 20 | + flow_id: Annotated[int, Body()], |
| 21 | + tag: Annotated[str, SystemString64], |
| 22 | + user: Annotated[User, Depends(fetch_user_or_raise)], |
| 23 | + expdb: Annotated[AsyncConnection, Depends(expdb_connection)], |
| 24 | +) -> dict[str, dict[str, Any]]: |
| 25 | + return await tag_entity( |
| 26 | + flow_id, |
| 27 | + tag, |
| 28 | + user, |
| 29 | + expdb, |
| 30 | + get_tags_fn=database.flows.get_tags, |
| 31 | + tag_fn=database.flows.tag, |
| 32 | + response_key="flow_tag", |
| 33 | + ) |
| 34 | + |
| 35 | + |
| 36 | +@router.post(path="/untag") |
| 37 | +async def untag_flow( |
| 38 | + flow_id: Annotated[int, Body()], |
| 39 | + tag: Annotated[str, SystemString64], |
| 40 | + user: Annotated[User, Depends(fetch_user_or_raise)], |
| 41 | + expdb: Annotated[AsyncConnection, Depends(expdb_connection)], |
| 42 | +) -> dict[str, dict[str, Any]]: |
| 43 | + return await untag_entity( |
| 44 | + flow_id, |
| 45 | + tag, |
| 46 | + user, |
| 47 | + expdb, |
| 48 | + get_tag_fn=database.flows.get_tag, |
| 49 | + delete_tag_fn=database.flows.delete_tag, |
| 50 | + get_tags_fn=database.flows.get_tags, |
| 51 | + response_key="flow_tag", |
| 52 | + ) |
| 53 | + |
| 54 | + |
15 | 55 | @router.get("/exists/{name}/{external_version}") |
16 | 56 | async def flow_exists( |
17 | 57 | name: str, |
|
0 commit comments