Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/app/api/docs/organization/list.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
List all organizations.

Returns paginated list of all organizations in the system.
Returns paginated list of all organizations in the system. The response includes a `has_more` field in `metadata` indicating whether additional pages are available.
3 changes: 3 additions & 0 deletions backend/app/api/docs/projects/list_by_org.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
List all projects for a given organization.

Returns all projects belonging to the specified organization ID. The organization must exist and be active.
11 changes: 8 additions & 3 deletions backend/app/api/routes/organization.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
from typing import List

from fastapi import APIRouter, Depends, HTTPException
from fastapi import APIRouter, Depends, HTTPException, Query
from sqlalchemy import func
from sqlmodel import select

Expand All @@ -27,14 +27,19 @@
response_model=APIResponse[List[OrganizationPublic]],
description=load_description("organization/list.md"),
)
def read_organizations(session: SessionDep, skip: int = 0, limit: int = 100):
def read_organizations(
session: SessionDep,
skip: int = Query(0, ge=0),
limit: int = Query(100, ge=1, le=100),
):
count_statement = select(func.count()).select_from(Organization)
count = session.exec(count_statement).one()

statement = select(Organization).offset(skip).limit(limit)
organizations = session.exec(statement).all()

return APIResponse.success_response(organizations)
has_more = (skip + limit) < count
return APIResponse.success_response(organizations, metadata={"has_more": has_more})
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this kind of support is not there in read projects endpoint as well so why are we only adding it to this one

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since this is requried for frontend that's why

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but how do you know that we wont require this for project in future

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but do u think organization would have lot of projects? .. for consistency I added the has_more metadata in projects endpoint as well



# Create a new organization
Expand Down
17 changes: 17 additions & 0 deletions backend/app/api/routes/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
from app.crud.project import (
create_project,
get_project_by_id,
get_projects_by_organization,
)
from app.crud.organization import validate_organization
from app.utils import APIResponse, load_description

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -112,3 +114,18 @@ def delete_project(session: SessionDep, project_id: int):
f"[delete_project] Project deleted successfully | project_id={project_id}"
)
return APIResponse.success_response(None)


# Get projects by organization
@router.get(
"/organization/{org_id}",
dependencies=[Depends(require_permission(Permission.SUPERUSER))],
response_model=APIResponse[List[ProjectPublic]],
description=load_description("projects/list_by_org.md"),
)
def read_projects_by_organization(
session: SessionDep, org_id: int
) -> APIResponse[List[ProjectPublic]]:
validate_organization(session=session, org_id=org_id)
projects = get_projects_by_organization(session=session, org_id=org_id)
return APIResponse.success_response(projects)
2 changes: 1 addition & 1 deletion backend/app/crud/organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ def validate_organization(session: Session, org_id: int) -> Organization:
logger.error(
f"[validate_organization] Organization is not active | 'org_id': {org_id}"
)
raise HTTPException("Organization is not active")
raise HTTPException(status_code=503, detail="Organization is not active")

return organization
Loading