Update app.py
Browse files
app.py
CHANGED
|
@@ -33,6 +33,16 @@ class Recipe(BaseModel):
|
|
| 33 |
ingredients: List[str]
|
| 34 |
instructions: str
|
| 35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
class DeleteRecipeRequest(BaseModel):
|
| 38 |
id: str
|
|
@@ -111,3 +121,21 @@ async def delete_recipe(data: DeleteRecipeRequest):
|
|
| 111 |
@app.get("/status")
|
| 112 |
def status():
|
| 113 |
return {"status": "ok"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
ingredients: List[str]
|
| 34 |
instructions: str
|
| 35 |
|
| 36 |
+
class RecipeUpdate(BaseModel):
|
| 37 |
+
name: Optional[str]
|
| 38 |
+
time: Optional[str]
|
| 39 |
+
creator: Optional[str]
|
| 40 |
+
category: Optional[str]
|
| 41 |
+
diff: Optional[str]
|
| 42 |
+
ingredients: Optional[List[str]]
|
| 43 |
+
description: Optional[str]
|
| 44 |
+
instructions: Optional[str]
|
| 45 |
+
user_id: Optional[str]
|
| 46 |
|
| 47 |
class DeleteRecipeRequest(BaseModel):
|
| 48 |
id: str
|
|
|
|
| 121 |
@app.get("/status")
|
| 122 |
def status():
|
| 123 |
return {"status": "ok"}
|
| 124 |
+
|
| 125 |
+
@app.patch("/supabase/edit/recipe")
|
| 126 |
+
async def edit_recipe(request: Request, id: str, update: RecipeUpdate):
|
| 127 |
+
try:
|
| 128 |
+
update_dict = update.dict(exclude_none=True)
|
| 129 |
+
if not update_dict:
|
| 130 |
+
raise HTTPException(status_code=400, detail="No fields provided to update.")
|
| 131 |
+
|
| 132 |
+
# Make the update
|
| 133 |
+
response = supabase.table("recipes").update(update_dict).eq("id", id).execute()
|
| 134 |
+
|
| 135 |
+
if response.error:
|
| 136 |
+
raise HTTPException(status_code=500, detail=response.error.message)
|
| 137 |
+
|
| 138 |
+
return {"message": "Recipe updated successfully.", "data": response.data}
|
| 139 |
+
|
| 140 |
+
except Exception as e:
|
| 141 |
+
raise HTTPException(status_code=500, detail=str(e))
|