Untitled

 avatar
unknown
python
a year ago
1.7 kB
6
Indexable
from fastapi import FastAPI, Depends, HTTPException
from sqlalchemy.orm import Session
from . import crud, models, schemas
from .database import SessionLocal, engine

models.Base.metadata.create_all(bind=engine)

app = FastAPI()

# Dependency
def get_db():
    db = SessionLocal()
    try:
        yield db
    finally:
        db.close()

@app.post("/bundle-products/", response_model=schemas.Product, tags=["Bundle Products"])
def create_bundle_product(product: schemas.ProductCreate, db: Session = Depends(get_db)):
    """Create a new bundle product and assign it to multiple categories."""
    return crud.create_bundle_product(db=db, product=product)

@app.put("/bundle-products/{product_id}", response_model=schemas.Product, tags=["Bundle Products"])
def update_bundle_product(product_id: int, product: schemas.ProductCreate, db: Session = Depends(get_db)):
    """Update an existing bundle product and reassign it to multiple categories."""
    db_product = crud.update_bundle_product(db, product_id=product_id, product=product)
    if db_product is None:
        raise HTTPException(status_code=404, detail="Product not found")
    return db_product

@app.get("/menu-details/", response_model=dict, tags=["Menu"])
def get_menu_details(menu_id: int, menu_temp_id: int, brand: str, concept_id: int, db: Session = Depends(get_db)):
    """Get menu details along with categories, products, services, display days, and steps."""
    result = crud.get_menu_details(db, menu_id, menu_temp_id, brand, concept_id)
    if result is None:
        raise HTTPException(status_code=404, detail="Menu not found")
    return result
Editor is loading...
Leave a Comment