REFACTOR API gateway fix 8

This commit is contained in:
Urtzi Alfaro
2025-07-26 23:29:57 +02:00
parent 1291d05183
commit 97ae58fb06
8 changed files with 997 additions and 375 deletions

View File

@@ -45,7 +45,7 @@ def get_training_service() -> TrainingService:
"""Factory function for TrainingService dependency"""
return TrainingService()
@router.post("/jobs", response_model=TrainingJobResponse)
@router.post("/tenants/{tenant_id}/jobs", response_model=TrainingJobResponse)
async def start_training_job(
request: TrainingJobRequest,
background_tasks: BackgroundTasks,
@@ -110,7 +110,7 @@ async def start_training_job(
tenant_id=tenant_id)
raise HTTPException(status_code=500, detail=f"Failed to start training job: {str(e)}")
@router.get("/jobs", response_model=List[TrainingJobResponse])
@router.get("/tenants/{tenant_id}/jobs", response_model=List[TrainingJobResponse])
async def get_training_jobs(
status: Optional[TrainingStatus] = Query(None, description="Filter jobs by status"),
limit: int = Query(100, ge=1, le=1000),
@@ -146,7 +146,7 @@ async def get_training_jobs(
tenant_id=tenant_id)
raise HTTPException(status_code=500, detail=f"Failed to get training jobs: {str(e)}")
@router.get("/jobs/{job_id}", response_model=TrainingJobResponse)
@router.get("/tenants/{tenant_id}/jobs/{job_id}", response_model=TrainingJobResponse)
async def get_training_job(
job_id: str,
tenant_id: UUID = Path(..., description="Tenant ID"),
@@ -179,7 +179,7 @@ async def get_training_job(
job_id=job_id)
raise HTTPException(status_code=500, detail=f"Failed to get training job: {str(e)}")
@router.get("/jobs/{job_id}/progress", response_model=TrainingJobProgress)
@router.get("/tenants/{tenant_id}/jobs/{job_id}/progress", response_model=TrainingJobProgress)
async def get_training_progress(
job_id: str,
tenant_id: UUID = Path(..., description="Tenant ID"),
@@ -209,7 +209,7 @@ async def get_training_progress(
job_id=job_id)
raise HTTPException(status_code=500, detail=f"Failed to get training progress: {str(e)}")
@router.post("/jobs/{job_id}/cancel")
@router.post("/tenants/{tenant_id}/jobs/{job_id}/cancel")
async def cancel_training_job(
job_id: str,
tenant_id: UUID = Path(..., description="Tenant ID"),
@@ -254,7 +254,7 @@ async def cancel_training_job(
job_id=job_id)
raise HTTPException(status_code=500, detail=f"Failed to cancel training job: {str(e)}")
@router.post("/products/{product_name}", response_model=TrainingJobResponse)
@router.post("/tenants/{tenant_id}/products/{product_name}", response_model=TrainingJobResponse)
async def train_single_product(
product_name: str,
request: SingleProductTrainingRequest,
@@ -309,7 +309,7 @@ async def train_single_product(
tenant_id=tenant_id)
raise HTTPException(status_code=500, detail=f"Failed to train product: {str(e)}")
@router.post("/validate", response_model=DataValidationResponse)
@router.post("/tenants/{tenant_id}/validate", response_model=DataValidationResponse)
async def validate_training_data(
request: DataValidationRequest,
tenant_id: UUID = Path(..., description="Tenant ID"),
@@ -340,7 +340,7 @@ async def validate_training_data(
tenant_id=tenant_id)
raise HTTPException(status_code=500, detail=f"Failed to validate data: {str(e)}")
@router.get("/models")
@router.get("/tenants/{tenant_id}/models")
async def get_trained_models(
product_name: Optional[str] = Query(None),
tenant_id: UUID = Path(..., description="Tenant ID"),
@@ -370,7 +370,7 @@ async def get_trained_models(
tenant_id=tenant_id)
raise HTTPException(status_code=500, detail=f"Failed to get models: {str(e)}")
@router.delete("/models/{model_id}")
@router.delete("/tenants/{tenant_id}/models/{model_id}")
@require_role("admin") # Only admins can delete models
async def delete_model(
model_id: str,
@@ -407,7 +407,7 @@ async def delete_model(
model_id=model_id)
raise HTTPException(status_code=500, detail=f"Failed to delete model: {str(e)}")
@router.get("/stats")
@router.get("/tenants/{tenant_id}/stats")
async def get_training_stats(
start_date: Optional[datetime] = Query(None),
end_date: Optional[datetime] = Query(None),
@@ -438,7 +438,7 @@ async def get_training_stats(
tenant_id=tenant_id)
raise HTTPException(status_code=500, detail=f"Failed to get stats: {str(e)}")
@router.post("/retrain/all")
@router.post("/tenants/{tenant_id}/retrain/all")
async def retrain_all_products(
request: TrainingJobRequest,
background_tasks: BackgroundTasks,