feat: Updated endpoint endpoints/names.post.py via AI

This commit is contained in:
Backend IM Bot 2025-04-12 21:10:36 +00:00
parent cbfe7608e7
commit 36b4df0e7c
2 changed files with 10 additions and 6 deletions

View File

@ -1,12 +1,15 @@
from fastapi import APIRouter, Depends, status from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session from sqlalchemy.orm import Session
from typing import List from typing import List
from core.database import get_db 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 = APIRouter()
@router.post("/names", status_code=status.HTTP_200_OK, response_model=List[str]) @router.post("/names", status_code=200, response_model=List[FruitSchema])
async def get_fruit_names(db: Session = Depends(get_db)): async def get_all_fruit_details(db: Session = Depends(get_db)):
"""Get all fruit names""" fruits = get_all_fruits(db)
return get_all_fruit_names(db) if not fruits:
raise HTTPException(status_code=404, detail="No fruits found")
return fruits

View File

@ -47,6 +47,7 @@ def get_fruit_by_name(db: Session, name: str) -> Optional[Fruit]:
def get_all_fruit_names(db: Session) -> List[str]: def get_all_fruit_names(db: Session) -> List[str]:
""" """
Retrieves a list of all fruit names. Retrieves a list of all fruit names.
This function is deprecated in favor of get_all_fruits() which returns full fruit objects.
Args: Args:
db (Session): The database session. db (Session): The database session.