46 lines
1.4 KiB
Python
46 lines
1.4 KiB
Python
"""STEP 01 — Import Batches (enhanced with source_code association)."""
|
|
from fastapi import APIRouter, Depends, HTTPException
|
|
|
|
from app.auth import CurrentUser
|
|
from app.config import settings
|
|
from app.db import list_batches, get_batch, get_batch_raw_records, get_batch_quality_summary
|
|
from app.project_context import ProjectContext, get_project_context
|
|
|
|
router = APIRouter()
|
|
|
|
|
|
@router.get("/batches")
|
|
async def _list(
|
|
source_code: str | None = None,
|
|
tenant_id: str | None = None,
|
|
project_id: str | None = None,
|
|
context: ProjectContext = Depends(get_project_context),
|
|
_user: CurrentUser = None,
|
|
):
|
|
return await list_batches(
|
|
tenant_id or context.tenant_id,
|
|
project_id or context.project_id,
|
|
source_code,
|
|
)
|
|
|
|
|
|
@router.get("/batches/{batch_id}")
|
|
async def _get(batch_id: int, _user: CurrentUser = None):
|
|
batch = await get_batch(batch_id)
|
|
if not batch:
|
|
raise HTTPException(404, "Batch not found")
|
|
return batch
|
|
|
|
|
|
@router.get("/batches/{batch_id}/raw-records")
|
|
async def _raw_records(batch_id: int, limit: int = 100, offset: int = 0, _user: CurrentUser = None):
|
|
return await get_batch_raw_records(batch_id, limit, offset)
|
|
|
|
|
|
@router.get("/batches/{batch_id}/quality-summary")
|
|
async def _quality(batch_id: int, _user: CurrentUser = None):
|
|
summary = await get_batch_quality_summary(batch_id)
|
|
if not summary:
|
|
raise HTTPException(404, "Batch not found")
|
|
return summary
|