feat: Generated endpoint endpoints/get-fruit-by-name.get.py via AI for Fruit
This commit is contained in:
parent
28d797b61c
commit
953a41a660
@ -0,0 +1,19 @@
|
||||
from fastapi import APIRouter, Depends, HTTPException
|
||||
from sqlalchemy.orm import Session
|
||||
from typing import Optional
|
||||
from core.database import get_db
|
||||
from schemas.fruit import FruitSchema
|
||||
from helpers.fruit_helpers import get_fruit_by_name, sanitize_fruit_name
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/get-fruit-by-name", response_model=Optional[FruitSchema])
|
||||
async def get_fruit_by_name_endpoint(
|
||||
name: str,
|
||||
db: Session = Depends(get_db)
|
||||
):
|
||||
sanitized_name = sanitize_fruit_name(name)
|
||||
fruit = get_fruit_by_name(db=db, name=sanitized_name)
|
||||
if not fruit:
|
||||
raise HTTPException(status_code=404, detail="Fruit not found")
|
||||
return fruit
|
Loading…
x
Reference in New Issue
Block a user