23 lines
858 B
Python
23 lines
858 B
Python
"""Organization-related API endpoints."""
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, Depends
|
|
|
|
from app.api.deps import get_current_user, get_organization_repository
|
|
from app.models.organization import OrganizationRead
|
|
from app.models.user import User
|
|
from app.repositories.org_repo import OrganizationRepository
|
|
|
|
router = APIRouter(prefix="/organizations", tags=["organizations"])
|
|
|
|
|
|
@router.get("/me", response_model=list[OrganizationRead])
|
|
async def list_user_organizations(
|
|
current_user: User = Depends(get_current_user),
|
|
repo: OrganizationRepository = Depends(get_organization_repository),
|
|
) -> list[OrganizationRead]:
|
|
"""Return organizations the authenticated user belongs to."""
|
|
|
|
organizations = await repo.list_for_user(current_user.id)
|
|
return [OrganizationRead.model_validate(org) for org in organizations]
|