diff --git a/endpoints/names.post.py b/endpoints/names.post.py index 3e6f779..e3c1b1a 100644 --- a/endpoints/names.post.py +++ b/endpoints/names.post.py @@ -1,12 +1,15 @@ -from fastapi import APIRouter, Depends, status +from fastapi import APIRouter, Depends, HTTPException from sqlalchemy.orm import Session from typing import List from core.database import get_db -from helpers.fruit_helpers import get_all_fruit_names +from schemas.fruit import FruitSchema +from helpers.fruit_helpers import get_all_fruits router = APIRouter() -@router.post("/names", status_code=status.HTTP_200_OK, response_model=List[str]) -async def get_fruit_names(db: Session = Depends(get_db)): - """Get all fruit names""" - return get_all_fruit_names(db) \ No newline at end of file +@router.post("/names", status_code=200, response_model=List[FruitSchema]) +async def get_all_fruit_details(db: Session = Depends(get_db)): + fruits = get_all_fruits(db) + if not fruits: + raise HTTPException(status_code=404, detail="No fruits found") + return fruits \ No newline at end of file diff --git a/helpers/fruit_helpers.py b/helpers/fruit_helpers.py index 834f030..57a6309 100644 --- a/helpers/fruit_helpers.py +++ b/helpers/fruit_helpers.py @@ -47,6 +47,7 @@ def get_fruit_by_name(db: Session, name: str) -> Optional[Fruit]: def get_all_fruit_names(db: Session) -> List[str]: """ Retrieves a list of all fruit names. + This function is deprecated in favor of get_all_fruits() which returns full fruit objects. Args: db (Session): The database session.