From 10d1ee859d598284e1289c617eb5d2c1db862a42 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Fri, 28 Mar 2025 18:31:09 +0000 Subject: [PATCH] Update code in endpoints/trees.get.py --- endpoints/trees.get.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/endpoints/trees.get.py b/endpoints/trees.get.py index e69de29..c79570a 100644 --- a/endpoints/trees.get.py +++ b/endpoints/trees.get.py @@ -0,0 +1,22 @@ +from fastapi import APIRouter, Depends, HTTPException, status +from sqlalchemy.orm import Session +from typing import List +from core.database import get_db +from models.tree import Tree +from schemas.tree import TreeSchema +from helpers.tree_helpers import get_all_trees + +router = APIRouter() + +@router.get("/trees", response_model=List[TreeSchema], status_code=status.HTTP_200_OK) +async def get_trees( + db: Session = Depends(get_db) +): + """Get all trees""" + trees = get_all_trees(db) + if not trees: + raise HTTPException( + status_code=status.HTTP_404_NOT_FOUND, + detail="No trees found" + ) + return trees \ No newline at end of file