From df66edb3824b71f1b29b5871b589d0ec5e423935 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Tue, 25 Mar 2025 13:12:19 -0500 Subject: [PATCH] Add Tree schema --- schemas/tree.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 schemas/tree.py diff --git a/schemas/tree.py b/schemas/tree.py new file mode 100644 index 0000000..ed58b88 --- /dev/null +++ b/schemas/tree.py @@ -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 + } + } \ No newline at end of file