adema5051's picture
Upload 8 files
95cb050 verified
"""
Pydantic models for API request/response validation
"""
from pydantic import BaseModel, field_validator
from typing import Optional
class SingleAssessment(BaseModel):
"""Model for single location vulnerability assessment request"""
latitude: float
longitude: float
height: Optional[float] = 0.0
basement: Optional[float] = 0.0
@field_validator('latitude')
@classmethod
def check_lat(cls, v: float) -> float:
if not -90 <= v <= 90:
raise ValueError('Latitude must be between -90 and 90')
return v
@field_validator('longitude')
@classmethod
def check_lon(cls, v: float) -> float:
if not -180 <= v <= 180:
raise ValueError('Longitude must be between -180 and 180')
return v
@field_validator('basement')
@classmethod
def check_basement(cls, v: float) -> float:
if v > 0:
raise ValueError('Basement height must be 0 or negative (e.g., -1, -2, -3)')
return v