diff --git a/app/main.py b/app/main.py index cc224e6..c989c2a 100644 --- a/app/main.py +++ b/app/main.py @@ -89,7 +89,7 @@ def read_schools(skip: int = 0, schools = crud.get_schools(db, skip=skip, limit=limit, filter_params=filter_params) if include_raw: return schools - return [school.dict(exclude={'raw'}) for school in schools] + return [school.model_dump(exclude={'raw'}) for school in schools] @app.get("/schools/{school_id}", response_model=schemas.School, response_model_exclude_none=True) @@ -99,7 +99,7 @@ def read_school(school_id: str, include_raw: bool = False, db: Session = Depends raise HTTPException(status_code=404, detail="School not found") if include_raw: return db_school - return db_school.dict(exclude={'raw'}) + return db_school.model_dump(exclude={'raw'}) @app.get("/stats", response_model=List[schemas.Statistic]) diff --git a/app/schemas.py b/app/schemas.py index 9ff8b9a..6684c17 100644 --- a/app/schemas.py +++ b/app/schemas.py @@ -5,7 +5,7 @@ from typing import Optional, List from geoalchemy2.shape import to_shape -from pydantic import BaseModel +from pydantic import ConfigDict, BaseModel from app import models @@ -33,31 +33,29 @@ class School(BaseModel): id: str name: str address: str - address2: Optional[str] - city: Optional[str] - director: Optional[str] - email: Optional[str] - fax: Optional[str] - latitude: Optional[float] - legal_status: Optional[str] - longitude: Optional[float] - phone: Optional[str] - provider: Optional[str] - school_type: Optional[str] - website: Optional[str] - zip: Optional[str] - raw: Optional[dict] - update_timestamp: Optional[datetime] - - class Config: - orm_mode = True + address2: Optional[str] = None + city: Optional[str] = None + director: Optional[str] = None + email: Optional[str] = None + fax: Optional[str] = None + latitude: Optional[float] = None + legal_status: Optional[str] = None + longitude: Optional[float] = None + phone: Optional[str] = None + provider: Optional[str] = None + school_type: Optional[str] = None + website: Optional[str] = None + zip: Optional[str] = None + raw: Optional[dict] = None + update_timestamp: Optional[datetime] = None + model_config = ConfigDict(from_attributes=True) @staticmethod def from_db(db_entry: models.School) -> School: if not db_entry.location: - return School.from_orm(db_entry) + return School.model_validate(db_entry) shape = to_shape(db_entry.location) - school = School.from_orm(db_entry) + school = School.model_validate(db_entry) school.latitude = shape.x school.longitude = shape.y return school @@ -66,17 +64,15 @@ def from_db(db_entry: models.School) -> School: class Statistic(BaseModel): state: State count: int - - class Config: - schema_extra = { - "example": [{ - "name": "BE", - "count": 10, - }, - {"name": "ND", - "count": 12} - ] - } + model_config = ConfigDict(json_schema_extra={ + "example": [{ + "name": "BE", + "count": 10, + }, + {"name": "ND", + "count": 12} + ] + }) class Params(BaseModel):