feat: Updated endpoint endpoints/names.post.py via AI
This commit is contained in:
parent
cbfe7608e7
commit
36b4df0e7c
@ -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
|
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user