Add Tree schema
This commit is contained in:
parent
35156a028e
commit
df66edb382
42
schemas/tree.py
Normal file
42
schemas/tree.py
Normal file
@ -0,0 +1,42 @@
|
||||
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
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user