Update code in endpoints/trees.get.py
This commit is contained in:
parent
0715181820
commit
10d1ee859d
@ -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
|
Loading…
x
Reference in New Issue
Block a user