73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
|
|
"""Organization API endpoints."""
|
||
|
|
|
||
|
|
from fastapi import APIRouter, Depends, status
|
||
|
|
|
||
|
|
from app.api.deps import CurrentUser, get_current_user, require_role
|
||
|
|
from app.schemas.org import (
|
||
|
|
MemberResponse,
|
||
|
|
NotificationTargetCreate,
|
||
|
|
NotificationTargetResponse,
|
||
|
|
OrgResponse,
|
||
|
|
ServiceCreate,
|
||
|
|
ServiceResponse,
|
||
|
|
)
|
||
|
|
from app.services import OrgService
|
||
|
|
|
||
|
|
|
||
|
|
router = APIRouter(prefix="/org", tags=["org"])
|
||
|
|
org_service = OrgService()
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("", response_model=OrgResponse)
|
||
|
|
async def get_org(current_user: CurrentUser = Depends(get_current_user)) -> OrgResponse:
|
||
|
|
"""Return the active organization summary for the authenticated user."""
|
||
|
|
|
||
|
|
return await org_service.get_current_org(current_user)
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/members", response_model=list[MemberResponse])
|
||
|
|
async def list_members(current_user: CurrentUser = Depends(require_role("admin"))) -> list[MemberResponse]:
|
||
|
|
"""List members of the current organization (admin only)."""
|
||
|
|
|
||
|
|
return await org_service.get_members(current_user)
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/services", response_model=list[ServiceResponse])
|
||
|
|
async def list_services(current_user: CurrentUser = Depends(get_current_user)) -> list[ServiceResponse]:
|
||
|
|
"""List services for the current organization."""
|
||
|
|
|
||
|
|
return await org_service.get_services(current_user)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/services", response_model=ServiceResponse, status_code=status.HTTP_201_CREATED)
|
||
|
|
async def create_service(
|
||
|
|
payload: ServiceCreate,
|
||
|
|
current_user: CurrentUser = Depends(require_role("member")),
|
||
|
|
) -> ServiceResponse:
|
||
|
|
"""Create a new service within the current organization (member+)."""
|
||
|
|
|
||
|
|
return await org_service.create_service(current_user, payload)
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/notification-targets", response_model=list[NotificationTargetResponse])
|
||
|
|
async def list_notification_targets(
|
||
|
|
current_user: CurrentUser = Depends(require_role("admin")),
|
||
|
|
) -> list[NotificationTargetResponse]:
|
||
|
|
"""List notification targets for the current organization (admin only)."""
|
||
|
|
|
||
|
|
return await org_service.get_notification_targets(current_user)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post(
|
||
|
|
"/notification-targets",
|
||
|
|
response_model=NotificationTargetResponse,
|
||
|
|
status_code=status.HTTP_201_CREATED,
|
||
|
|
)
|
||
|
|
async def create_notification_target(
|
||
|
|
payload: NotificationTargetCreate,
|
||
|
|
current_user: CurrentUser = Depends(require_role("admin")),
|
||
|
|
) -> NotificationTargetResponse:
|
||
|
|
"""Create a notification target for the current organization (admin only)."""
|
||
|
|
|
||
|
|
return await org_service.create_notification_target(current_user, payload)
|