diff --git a/endpoints/fruits.delete.py b/endpoints/fruits.delete.py index 1486cf6..5529840 100644 --- a/endpoints/fruits.delete.py +++ b/endpoints/fruits.delete.py @@ -1,15 +1,14 @@ from fastapi import APIRouter, HTTPException, status from schemas.fruit import FruitSchema -from helpers.fruit_helpers import delete_fruit, get_fruit_by_id +from helpers.fruit_helpers import get_fruit_by_id, delete_fruit from sqlalchemy.orm import Session from fastapi import Depends from core.database import get_db -import uuid router = APIRouter() @router.delete("/fruits/{fruit_id}", status_code=status.HTTP_200_OK, response_model=FruitSchema) -async def delete_fruit_endpoint(fruit_id: uuid.UUID, db: Session = Depends(get_db)): +async def delete_fruit_endpoint(fruit_id: str, db: Session = Depends(get_db)): fruit = get_fruit_by_id(db, fruit_id) if not fruit: raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="Fruit not found") diff --git a/helpers/fruit_helpers.py b/helpers/fruit_helpers.py index cf1b382..4d31c14 100644 --- a/helpers/fruit_helpers.py +++ b/helpers/fruit_helpers.py @@ -68,4 +68,6 @@ def delete_fruit(db: Session, fruit_id: UUID) -> None: fruit = db.query(Fruit).filter(Fruit.id == fruit_id).first() if fruit: db.delete(fruit) - db.commit() \ No newline at end of file + db.commit() + else: + raise ValueError(f"No fruit found with ID {fruit_id}") \ No newline at end of file