flip_api.project_services.get_projects

Attributes

router

Functions

get_projects_paginated_orm(...)

Fetches paginated project data from the database using SQLModel ORM.

_load_latest_query_per_project(→ dict[uuid.UUID, ...)

Batch-load most-recent cohort query + cohort size for each project.

_load_latest_audit_at_per_project(→ dict[uuid.UUID, str])

Batch-load the most recent projects_audit timestamp per project for a given action.

_load_user_counts(→ dict[uuid.UUID, int])

Per-project user count.

get_projects_endpoint(, user_id)

Get a paginated and filtered list of projects.

Module Contents

flip_api.project_services.get_projects.router
flip_api.project_services.get_projects.get_projects_paginated_orm(session: sqlmodel.Session, user_id: uuid.UUID | None, paging_details: flip_api.utils.paging_utils.PagingInfo, filter_details: flip_api.utils.paging_utils.FilterInfo) flip_api.utils.paging_utils.IPagedResponse[flip_api.domain.interfaces.project.IProject]

Fetches paginated project data from the database using SQLModel ORM.

Parameters:
  • session (Session) – The SQLModel session used for the database queries.

  • user_id (UUID | None) – The requesting user’s ID. When provided, results are restricted to projects the user owns or has explicit access to.

  • paging_details (PagingInfo) – Page size, offset, and optional search string.

  • filter_details (FilterInfo) – Additional filter criteria (e.g. owner ID).

Returns:

Paginated list of projects and total row count.

Return type:

IPagedResponse[IProject]

flip_api.project_services.get_projects._load_latest_query_per_project(project_ids: list[uuid.UUID], session: sqlmodel.Session) dict[uuid.UUID, flip_api.domain.interfaces.project.IProjectQuery]

Batch-load most-recent cohort query + cohort size for each project.

Avoids the N+1 cost of calling the per-project query loader on every row. Three queries total: pick the latest Queries row per project, then batch the trust counts and the cohort totals for the picked query IDs.

Parameters:
  • project_ids – Project IDs to load queries for.

  • session – Active SQLModel session.

Returns:

Mapping project_id → IProjectQuery for projects that have at least one cohort query. Projects without one are omitted from the result.

flip_api.project_services.get_projects._load_latest_audit_at_per_project(project_ids: list[uuid.UUID], action: flip_api.domain.schemas.actions.ProjectAuditAction, session: sqlmodel.Session) dict[uuid.UUID, str]

Batch-load the most recent projects_audit timestamp per project for a given action.

One SQL round-trip — useful for surfacing stage transition dates (STAGE, APPROVE, UNSTAGE, etc.) without paying the N+1 cost of per-project audit lookups.

flip_api.project_services.get_projects._load_user_counts(project_ids: list[uuid.UUID], session: sqlmodel.Session) dict[uuid.UUID, int]

Per-project user count.

The owner is auto-added to ProjectUserAccess on project creation, so this count includes them and the UI doesn’t need to +1.

flip_api.project_services.get_projects.get_projects_endpoint(request: fastapi.Request, session: sqlmodel.Session = Depends(get_session), user_id: uuid.UUID = Depends(verify_token)) flip_api.utils.paging_utils.IPagedData[flip_api.domain.interfaces.project.IProject]

Get a paginated and filtered list of projects.

Parameters:
  • request (Request) – The HTTP request object, used to access query parameters.

  • session (Session) – The database session for querying.

  • user_id (UUID) – The ID of the user making the request.

Returns:

A paginated response containing the projects.

Return type:

IPagedData[IProject]

Raises:

HTTPException – If an error occurs while fetching projects.