feat: Generated endpoint endpoints/get-fruit-by-color.get.py via AI for Fruit

This commit is contained in:
Backend IM Bot 2025-04-14 14:39:03 +00:00
parent a24fee2362
commit e0ec828be7

View File

@ -0,0 +1,23 @@
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from typing import List
from core.database import get_db
from schemas.fruit import FruitSchema
from helpers.fruit_helpers import get_fruits_by_color, normalize_color_name
router = APIRouter()
@router.get("/get-fruit-by-color", response_model=List[FruitSchema])
async def get_fruits_by_color_endpoint(
color: str,
db: Session = Depends(get_db)
):
"""Get fruits by their color"""
normalized_color = normalize_color_name(color)
fruits = get_fruits_by_color(db=db, color=normalized_color)
if not fruits:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"No fruits found with color: {normalized_color}"
)
return fruits