Add improvements

This commit is contained in:
Urtzi Alfaro
2026-01-12 14:24:14 +01:00
parent 6037faaf8c
commit 230bbe6a19
61 changed files with 1668 additions and 894 deletions

View File

@@ -9,6 +9,7 @@ from fastapi.responses import JSONResponse
from typing import List, Dict, Any, Optional
from datetime import date, datetime, timezone
import uuid
from uuid import UUID
from app.services.forecasting_service import EnhancedForecastingService
from app.services.prediction_service import PredictionService
@@ -42,6 +43,30 @@ async def get_rate_limiter():
return create_rate_limiter(redis_client)
def validate_uuid(value: str, field_name: str = "ID") -> str:
"""
Validate that a string is a valid UUID.
Args:
value: The string to validate
field_name: Name of the field for error messages
Returns:
The validated UUID string
Raises:
HTTPException: If the value is not a valid UUID
"""
try:
UUID(value)
return value
except (ValueError, AttributeError):
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
detail=f"{field_name} must be a valid UUID, got: {value}"
)
def get_enhanced_forecasting_service():
"""Dependency injection for EnhancedForecastingService"""
database_manager = create_database_manager(settings.DATABASE_URL, "forecasting-service")
@@ -68,6 +93,10 @@ async def generate_single_forecast(
enhanced_forecasting_service: EnhancedForecastingService = Depends(get_enhanced_forecasting_service)
):
"""Generate a single product forecast with caching support"""
# Validate UUID fields
validate_uuid(tenant_id, "tenant_id")
# inventory_product_id already validated by ForecastRequest schema
metrics = get_metrics_collector(request_obj)
try: