42 lines
1.3 KiB
Python
42 lines
1.3 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Optional
|
|
|
|
# Base schema
|
|
class TreeBase(BaseModel):
|
|
name: str = Field(..., description="Name of the tree")
|
|
species: str = Field(..., description="Species of the tree")
|
|
height: int = Field(..., gt=0, description="Height of the tree in meters")
|
|
diameter: int = Field(..., gt=0, description="Diameter of the tree in centimeters")
|
|
|
|
# Schema for creating a new Tree
|
|
class TreeCreate(TreeBase):
|
|
location_id: int = Field(..., gt=0, description="ID of the location where the tree is located")
|
|
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "Oak Tree",
|
|
"species": "Quercus robur",
|
|
"height": 15,
|
|
"diameter": 80,
|
|
"location_id": 1
|
|
}
|
|
}
|
|
|
|
# Schema for Tree responses
|
|
class TreeResponse(TreeBase):
|
|
id: int = Field(..., gt=0, description="ID of the tree")
|
|
location_id: int = Field(..., gt=0, description="ID of the location where the tree is located")
|
|
|
|
class Config:
|
|
orm_mode = True
|
|
schema_extra = {
|
|
"example": {
|
|
"id": 1,
|
|
"name": "Oak Tree",
|
|
"species": "Quercus robur",
|
|
"height": 15,
|
|
"diameter": 80,
|
|
"location_id": 1
|
|
}
|
|
} |