Skip to content

project

view_project(id=None, user_id=None, user=Depends(current_active_superuser), db=Depends(get_async_db)) async

Query ProjectV2 table.

Parameters:

Name Type Description Default
id Optional[int]

If not None, select a given project.id.

None
user_id Optional[int]

If not None, select a given project.user_id.

None
Source code in fractal_server/app/routes/admin/v2/project.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@router.get("/", response_model=list[ProjectReadV2])
async def view_project(
    id: Optional[int] = None,
    user_id: Optional[int] = None,
    user: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
) -> list[ProjectReadV2]:
    """
    Query `ProjectV2` table.

    Args:
        id: If not `None`, select a given `project.id`.
        user_id: If not `None`, select a given `project.user_id`.
    """

    stm = select(ProjectV2)

    if id is not None:
        stm = stm.where(ProjectV2.id == id)
    if user_id is not None:
        stm = stm.where(ProjectV2.user_list.any(UserOAuth.id == user_id))

    res = await db.execute(stm)
    project_list = res.scalars().all()
    await db.close()

    return project_list