Add improvements
This commit is contained in:
@@ -9,6 +9,7 @@ from pydantic import BaseModel, Field, validator
|
||||
from datetime import datetime, date
|
||||
from typing import Optional, List, Dict, Any
|
||||
from enum import Enum
|
||||
from uuid import UUID
|
||||
|
||||
class BusinessType(str, Enum):
|
||||
INDIVIDUAL = "individual"
|
||||
@@ -22,10 +23,19 @@ class ForecastRequest(BaseModel):
|
||||
forecast_date: date = Field(..., description="Starting date for forecast")
|
||||
forecast_days: int = Field(1, ge=1, le=30, description="Number of days to forecast")
|
||||
location: str = Field(..., description="Location identifier")
|
||||
|
||||
|
||||
# Optional parameters - internally handled
|
||||
confidence_level: float = Field(0.8, ge=0.5, le=0.95, description="Confidence level")
|
||||
|
||||
|
||||
@validator('inventory_product_id')
|
||||
def validate_inventory_product_id(cls, v):
|
||||
"""Validate that inventory_product_id is a valid UUID"""
|
||||
try:
|
||||
UUID(v)
|
||||
except (ValueError, AttributeError):
|
||||
raise ValueError(f"inventory_product_id must be a valid UUID, got: {v}")
|
||||
return v
|
||||
|
||||
@validator('forecast_date')
|
||||
def validate_forecast_date(cls, v):
|
||||
if v < date.today():
|
||||
@@ -39,6 +49,26 @@ class BatchForecastRequest(BaseModel):
|
||||
inventory_product_ids: List[str] = Field(..., description="List of inventory product IDs")
|
||||
forecast_days: int = Field(7, ge=1, le=30, description="Number of days to forecast")
|
||||
|
||||
@validator('tenant_id')
|
||||
def validate_tenant_id(cls, v):
|
||||
"""Validate that tenant_id is a valid UUID if provided"""
|
||||
if v is not None:
|
||||
try:
|
||||
UUID(v)
|
||||
except (ValueError, AttributeError):
|
||||
raise ValueError(f"tenant_id must be a valid UUID, got: {v}")
|
||||
return v
|
||||
|
||||
@validator('inventory_product_ids')
|
||||
def validate_inventory_product_ids(cls, v):
|
||||
"""Validate that all inventory_product_ids are valid UUIDs"""
|
||||
for product_id in v:
|
||||
try:
|
||||
UUID(product_id)
|
||||
except (ValueError, AttributeError):
|
||||
raise ValueError(f"All inventory_product_ids must be valid UUIDs, got invalid: {product_id}")
|
||||
return v
|
||||
|
||||
class ForecastResponse(BaseModel):
|
||||
"""Response schema for forecast results"""
|
||||
id: str
|
||||
|
||||
Reference in New Issue
Block a user