organization.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. """
  2. Client endpoints for viewing organization info.
  3. """
  4. from typing import Annotated
  5. from fastapi import APIRouter, Depends, HTTPException, status
  6. from sqlalchemy.ext.asyncio import AsyncSession
  7. from app.api.deps import get_current_user
  8. from app.core.database import get_db
  9. from app.models.user import User
  10. from app.schemas.organization import OrganizationResponse
  11. from app.services import organization_service
  12. router = APIRouter()
  13. @router.get("/me", response_model=OrganizationResponse)
  14. async def get_my_organization(
  15. db: Annotated[AsyncSession, Depends(get_db)],
  16. current_user: Annotated[User, Depends(get_current_user)],
  17. ):
  18. """
  19. Get current user's organization.
  20. Returns organization details for the current user.
  21. """
  22. if not current_user.organization_id:
  23. raise HTTPException(
  24. status_code=status.HTTP_404_NOT_FOUND,
  25. detail="User is not assigned to any organization",
  26. )
  27. org = await organization_service.get_organization(
  28. db, current_user.organization_id
  29. )
  30. if not org:
  31. raise HTTPException(
  32. status_code=status.HTTP_404_NOT_FOUND,
  33. detail="Organization not found",
  34. )
  35. return org