示例#1
0
def update_customer(cid: int, customer: schemas.CustomerRequestUpdate, dbb: Session = Depends(get_db)):
    prev_customer = get_customer_by_id_if_exists(cid, dbb)

    customer_update = schemas.CustomerUpdate(
        customer_id=cid,
        phone_number=customer.phone_number if customer.phone_number else prev_customer.phone_number,
        address=customer.address if customer.address else prev_customer.address,
    )

    return Crud.update_customer(dbb=dbb, customer=customer_update)
def update_drink(
        did: int,
        drink: schemas.DrinkRequestUpdate,
        dbb: Session = Depends(get_db),
):

    prev_drink = get_drink_by_id_if_exists(did, dbb)
    drink_update = schemas.DrinkUpdate(
        drink_id=did,
        name=drink.name if drink.name else prev_drink.name,
        price=drink.price if drink.price else prev_drink.price,
    )
    return Crud.update_drink(dbb, drink_update)
示例#3
0
def update_topping(
        tid: int,
        topping: schemas.ToppingRequestUpdate,
        dbb: Session = Depends(get_db),
):

    prev_top = get_topping_by_id_if_exists(tid, dbb)
    topping_update = schemas.ToppingUpdate(
        topping_id=tid,
        name=topping.name if topping.name else prev_top.name,
        price=topping.price if topping.price else prev_top.price,
    )
    return Crud.update_topping(dbb, topping_update)
示例#4
0
def update_pizza(
        pid: int,
        pizza: schemas.PizzaRequestUpdate,
        dbb: Session = Depends(get_db),
):
    prev_pizza = get_pizza_by_id_if_exists(pid, dbb)

    toppings = []
    for tid in pizza.toppings:
        ftop = get_topping_by_id_if_exists(tid, dbb)
        toppings.append(ftop)

    pizza_update = schemas.PizzaUpdate(
        pizza_id=pid,
        name=pizza.name if pizza.name else prev_pizza.name,
        size=pizza.size if pizza.size else prev_pizza.size,
        base_price=pizza.base_price
        if pizza.base_price else prev_pizza.base_price,
        toppings=toppings if toppings else prev_pizza.toppings,
    )
    return Crud.update_pizza(dbb, pizza_update)
def create_drink(drink: schemas.DrinkCreate, dbb: Session = Depends(get_db)):
    return Crud.create_drink(dbb, drink)
def read_drinks(dbb: Session = Depends(get_db)):
    return Crud.get_drinks(dbb=dbb)
示例#7
0
def delete_pizza(pid: int, dbb: Session = Depends(get_db)):
    get_pizza_by_id_if_exists(pid, dbb)
    return Crud.delete_pizza(dbb, pid)
示例#8
0
def create_topping(topping: schemas.ToppingCreate,
                   dbb: Session = Depends(get_db)):
    return Crud.create_topping(dbb, topping)
示例#9
0
def get_customer_by_id_if_exists(cid: int, dbb: Session):
    customer = Crud.get_customer_by_id(dbb, cid)
    if not customer:
        raise Exception(f"No such customer with {cid} found.")
    return customer
示例#10
0
def get_drink_by_id_if_exists(did: int, dbb: Session):
    drink = Crud.get_drink_by_id(dbb, did)
    if not drink:
        raise Exception(f"No such drink with {did} found.")
    return drink
示例#11
0
def remove_order_for_customer(cid: int, oid: int, dbb: Session = Depends(get_db)):
    get_customer_by_id_if_exists(cid, dbb)
    get_order_by_id_if_exists(oid, dbb)
    return Crud.remove_order_for_customer(dbb, cid, oid)
示例#12
0
def add_order_to_customer(cid: int, oid: int, dbb: Session = Depends(get_db)):
    get_customer_by_id_if_exists(cid, dbb)
    get_order_by_id_if_exists(oid, dbb)
    return Crud.add_order_to_customer(dbb, cid, oid)
示例#13
0
def read_customers(dbb: Session = Depends(get_db)):
    return Crud.get_customers(dbb=dbb)
示例#14
0
def create_customer(customer: schemas.CustomerCreate, dbb: Session = Depends(get_db)):
    return Crud.create_customer(dbb, customer)
示例#15
0
def delete_topping(tid: int, dbb: Session = Depends(get_db)):
    get_topping_by_id_if_exists(tid, dbb)
    return Crud.delete_topping(dbb, tid)
def delete_drink(did: int, dbb: Session = Depends(get_db)):
    get_drink_by_id_if_exists(did, dbb)
    return Crud.delete_drink(dbb, did)
示例#17
0
def get_topping_by_id_if_exists(tid: int, dbb: Session):
    topping = Crud.get_topping_by_id(dbb, tid)
    if not topping:
        raise Exception(f"No such topping with {tid} found.")
    return topping
示例#18
0
def read_pizzas(dbb: Session = Depends(get_db)):
    return Crud.get_pizzas(dbb=dbb)
示例#19
0
def get_order_by_id_if_exists(oid: int, dbb: Session):
    order = Crud.get_order_by_id(dbb, oid)
    if not order:
        raise Exception(f"No such order with {oid} found.")
    return order
示例#20
0
def create_pizza(pizza: schemas.PizzaCreate, dbb: Session = Depends(get_db)):
    return Crud.create_pizza(dbb, pizza)
示例#21
0
def get_pizza_by_id_if_exists(pid: int, dbb: Session):
    pizza = Crud.get_pizza_by_id(dbb, pid)
    if not pizza:
        raise Exception(f"No such pizza with {pid} found.")
    return pizza
示例#22
0
def read_toppings(dbb: Session = Depends(get_db)):
    return Crud.get_toppings(dbb=dbb)