From e0ec828be7f955f51ec228b81646646f73829519 Mon Sep 17 00:00:00 2001 From: Backend IM Bot Date: Mon, 14 Apr 2025 14:39:03 +0000 Subject: [PATCH] feat: Generated endpoint endpoints/get-fruit-by-color.get.py via AI for Fruit --- endpoints/get-fruit-by-color.get.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/endpoints/get-fruit-by-color.get.py b/endpoints/get-fruit-by-color.get.py index e69de29..ffea04e 100644 --- a/endpoints/get-fruit-by-color.get.py +++ b/endpoints/get-fruit-by-color.get.py @@ -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 \ No newline at end of file