44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""STEP 01 — Source Profiles CRUD."""
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from app.auth import CurrentUser
|
|
from app.config import settings
|
|
from app.contracts import SourceProfileCreate, SourceProfileUpdate
|
|
from app.db import list_source_profiles, create_source_profile, update_source_profile
|
|
from app.project_context import ProjectContext, get_project_context
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/source-profiles")
|
|
async def _list(
|
|
tenant_id: str | None = None,
|
|
project_id: str | None = None,
|
|
context: ProjectContext = Depends(get_project_context),
|
|
_user: CurrentUser = None,
|
|
):
|
|
return await list_source_profiles(
|
|
tenant_id or context.tenant_id,
|
|
project_id or context.project_id,
|
|
)
|
|
|
|
|
|
@router.post("/source-profiles")
|
|
async def _create(
|
|
body: SourceProfileCreate,
|
|
context: ProjectContext = Depends(get_project_context),
|
|
_user: CurrentUser = None,
|
|
):
|
|
data = body.model_dump()
|
|
data.setdefault("tenant_id", context.tenant_id)
|
|
data.setdefault("project_id", context.project_id)
|
|
return await create_source_profile(data)
|
|
|
|
|
|
@router.patch("/source-profiles/{profile_id}")
|
|
async def _update(profile_id: int, body: SourceProfileUpdate, _user: CurrentUser):
|
|
row = await update_source_profile(profile_id, body.model_dump(exclude_none=True))
|
|
if not row:
|
|
raise HTTPException(404, "Source profile not found")
|
|
return row
|