refactor: Modify PUT /fruits endpoint to return updated fruit in data object ✅ (auto-linted)
This commit is contained in:
parent
034dc8341d
commit
1f41289194
@ -1,20 +1,15 @@
|
||||
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
|
||||
from fastapi import APIRouter, Depends
|
||||
from typing import Dict
|
||||
from helpers.fruit_helpers import update_fruit
|
||||
from schemas.fruit import FruitSchema
|
||||
from db import get_db, Session
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.put("/fruits", status_code=200, response_model=FruitSchema)
|
||||
@router.put("/fruits", response_model=Dict[str, FruitSchema])
|
||||
async def update_fruit_endpoint(
|
||||
fruit_id: str,
|
||||
fruit_data: FruitUpdate,
|
||||
fruit_update: FruitSchema,
|
||||
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
|
||||
updated_fruit = update_fruit(db=db, fruit_update=fruit_update)
|
||||
return {"data": updated_fruit}
|
@ -10,3 +10,4 @@ alembic>=1.13.1
|
||||
jose
|
||||
passlib
|
||||
pydantic
|
||||
db
|
||||
|
@ -16,6 +16,9 @@ class FruitUpdate(FruitBase):
|
||||
description: Optional[str] = Field(None, description="Description of the fruit")
|
||||
price: Optional[int] = Field(None, description="Price of the fruit")
|
||||
|
||||
class FruitResponse(BaseModel):
|
||||
data: FruitBase
|
||||
|
||||
class FruitSchema(FruitBase):
|
||||
id: uuid.UUID
|
||||
created_at: datetime
|
||||
|
Loading…
x
Reference in New Issue
Block a user