feat: Generated endpoint endpoints/get-fruit-by-color.get.py via AI for Fruit
This commit is contained in:
parent
a24fee2362
commit
e0ec828be7
@ -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
|
Loading…
x
Reference in New Issue
Block a user