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 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)
@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

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]:
"""
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.