20 lines
661 B
Python
20 lines
661 B
Python
from fastapi import APIRouter, Depends, HTTPException
|
|
from sqlalchemy.orm import Session
|
|
from core.database import get_db
|
|
from schemas.fruit import FruitSchema, FruitUpdate
|
|
from helpers.fruit_helpers import get_fruit_by_id, update_fruit
|
|
|
|
router = APIRouter()
|
|
|
|
@router.put("/fruits", status_code=200, response_model=FruitSchema)
|
|
async def update_fruit_endpoint(
|
|
fruit_id: str,
|
|
fruit_data: FruitUpdate,
|
|
db: Session = Depends(get_db)
|
|
):
|
|
fruit = get_fruit_by_id(db, fruit_id)
|
|
if not fruit:
|
|
raise HTTPException(status_code=404, detail="Fruit not found")
|
|
|
|
updated_fruit = update_fruit(db, fruit_id, fruit_data)
|
|
return updated_fruit |