feat: implement shop CRUD operations and fix address deletion bug

- Add shop creation, editing, and deletion functionality
- Create AddShopModal and ConfirmDeleteModal components
- Add missing backend PUT/DELETE endpoints for shops
- Fix address field not clearing when edited to empty value
This commit is contained in:
2025-05-25 12:56:56 +02:00
parent cd39ac1fe8
commit 500cb8983c
5 changed files with 355 additions and 4 deletions

View File

@@ -94,6 +94,30 @@ def read_shop(shop_id: int, db: Session = Depends(get_db)):
raise HTTPException(status_code=404, detail="Shop not found")
return shop
@app.put("/shops/{shop_id}", response_model=schemas.Shop)
def update_shop(shop_id: int, shop_update: schemas.ShopUpdate, db: Session = Depends(get_db)):
shop = db.query(models.Shop).filter(models.Shop.id == shop_id).first()
if shop is None:
raise HTTPException(status_code=404, detail="Shop not found")
update_data = shop_update.dict()
for field, value in update_data.items():
setattr(shop, field, value)
db.commit()
db.refresh(shop)
return shop
@app.delete("/shops/{shop_id}")
def delete_shop(shop_id: int, db: Session = Depends(get_db)):
shop = db.query(models.Shop).filter(models.Shop.id == shop_id).first()
if shop is None:
raise HTTPException(status_code=404, detail="Shop not found")
db.delete(shop)
db.commit()
return {"message": "Shop deleted successfully"}
# Shopping Event endpoints
@app.post("/shopping-events/", response_model=schemas.ShoppingEventResponse)
def create_shopping_event(event: schemas.ShoppingEventCreate, db: Session = Depends(get_db)):