Example #1
0
def update_order(order_id, order: OrderInUpdate):
    order_id = int(order_id)
    index = next((i for i, order in enumerate(db.table["order"])
                  if order["id"] == order_id), -1)
    if index < 0:
        raise HTTPException(status_code=404, detail="Not Found")

    if order.customer_id is not None:
        db.table["order"][index]["customer_id"] = order.customer_id
    if order.cook_id is not None:
        db.table["order"][index]["cook_id"] = order.cook_id
    if order.rider_id is not None:
        db.table["order"][index]["rider_id"] = order.rider_id
    if order.date_start is not None:
        db.table["order"][index]["date_start"] = order.date_start
    if order.date_end is not None:
        db.table["order"][index]["date_end"] = order.date_end
    if order.status is not None:
        db.table["order"][index]["status"] = order.status
    if order.address is not None:
        db.table["order"][index]["address"] = order.address
    if order.contact is not None:
        db.table["order"][index]["contact"] = order.contact
    if order.credit_card_number is not None:
        db.table["order"][index][
            "credit_card_number"] = order.credit_card_number
    if order.order_details is not None:
        db.table["order"][index]["order_details"] = order.order_details
    db.commit()
    return {"success": True}
Example #2
0
def delete_order(order_id):
    order_id = int(order_id)
    index = next((i for i, order in enumerate(db.table["order"])
                  if order["id"] == order_id), -1)
    if index < 0:
        raise HTTPException(status_code=404, detail="Not Found")
    del db.table["order"][index]
    db.commit()
    return {"success": True}
Example #3
0
def delete_item(item_id):
    item_id = int(item_id)
    index = next(
        (i
         for i, item in enumerate(db.table["item"]) if item["id"] == item_id),
        -1)
    if index < 0:
        raise HTTPException(status_code=404, detail="Not Found")
    del db.table["item"][index]
    db.commit()
    return {"success": True}
Example #4
0
def delete_dinner_menu(dinner_menu_id):
    dinner_menu_id = int(dinner_menu_id)
    index = next((i for i, dinner_menu in enumerate(db.table["dinner_menu"])
                  if dinner_menu["id"] == dinner_menu_id), -1)
    if index < 0:
        raise HTTPException(status_code=404, detail="Not Found")
    del db.table["dinner_menu"][index]
    db.commit()
    return {
        "success": True
    }
Example #5
0
def delete_user(user_id, current_user: User = Depends(get_current_user)):
    user_id = int(user_id)
    if current_user["type"] == "customer" and current_user["id"] != user_id:
        raise HTTPException(statue_code=403, detail="Forbidden")
    index = next(
        (i
         for i, item in enumerate(db.table["user"]) if item["id"] == user_id),
        -1)
    if index < 0:
        raise HTTPException(status_code=404, detail="Not Found")

    del db.table["user"][index]
    db.commit()
    return {"success": True}
Example #6
0
def create_item(item: ItemInCreate):
    itemFound = [x for x in db.table["item"] if x["name"] == item.name]
    if len(itemFound) > 0:
        raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
                            detail="Duplicated item name")
    payload = {}
    payload["id"] = len(db.table["item"])
    payload["name"] = item.name
    payload["type"] = item.type
    payload["price"] = item.price
    payload["stock"] = item.stock
    db.table["item"].append(payload)
    db.commit()
    return {"success": True}
Example #7
0
def sign_up(user: UserInRegister):
    userFound = [x for x in db.table["user"] if x["username"] == user.username]
    if len(userFound) > 0:
        raise HTTPException(status_code=HTTP_401_UNAUTHORIZED)
    payload = {}
    payload["id"] = len(db.table["user"])
    payload["username"] = user.username
    payload["hashed_password"] = get_password_hash(user.password)
    payload["address"] = user.address
    payload["contact"] = user.contact
    payload["type"] = "customer"
    payload["important"] = False
    db.table["user"].append(payload)
    db.commit()
    return {"success": True}
Example #8
0
def update_dinner_menu(dinner_menu_id, dinner_menu: DinnerMenuInUpdate):
    dinner_menu_id = int(dinner_menu_id)
    index = next((i for i, dinner_menu in enumerate(db.table["dinner_menu"])
                  if dinner_menu["id"] == dinner_menu_id), -1)
    if index < 0:
        raise HTTPException(status_code=404, detail="Not Found")

    if dinner_menu.name is not None:
        db.table["dinner_menu"][index]["name"] = dinner_menu.name
    if dinner_menu.items is not None:
        db.table["dinner_menu"][index]["items"] = dinner_menu.items
    db.commit()
    return {
        "success": True
    }
Example #9
0
def create_dinner_menu(dinner_menu: DinnerMenuInCreate):
    dinnerMenuFound = [x for x in db.table["dinner_menu"]
                       if x["name"] == dinner_menu.name]
    if len(dinnerMenuFound) > 0:
        raise HTTPException(
            status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail="Duplicated dinner_menu name")
    payload = {}
    payload["id"] = len(db.table["dinner_menu"])
    payload["name"] = dinner_menu.name
    payload["items"] = dinner_menu.items
    db.table["dinner_menu"].append(payload)
    db.commit()
    return {
        "success": True
    }
Example #10
0
def create_order(order: OrderInCreate):
    payload = {}
    payload["id"] = len(db.table["order"])
    payload["customer_id"] = order.customer_id
    payload["cook_id"] = order.cook_id
    payload["rider_id"] = order.rider_id
    payload["date_start"] = order.date_start
    payload["date_end"] = order.date_end
    payload["status"] = order.status
    payload["address"] = order.address
    payload["contact"] = order.contact
    payload["credit_card_number"] = order.credit_card_number
    payload["order_details"] = order.order_details
    db.table["order"].append(payload)
    db.commit()
    return {"success": True}
Example #11
0
def update_item(item_id, item: ItemInUpdate):
    item_id = int(item_id)
    index = next(
        (i
         for i, item in enumerate(db.table["item"]) if item["id"] == item_id),
        -1)
    if index < 0:
        raise HTTPException(status_code=404, detail="Not Found")

    if item.name is not None:
        db.table["item"][index]["name"] = item.name
    if item.type is not None:
        db.table["item"][index]["type"] = item.type
    if item.price is not None:
        db.table["item"][index]["price"] = item.price
    if item.stock is not None:
        db.table["item"][index]["stock"] = item.stock
    db.commit()
    return {"success": True}
Example #12
0
def create_user(user: UserInCreate,
                current_user: User = Depends(get_current_user)):
    if current_user["type"] == "customer":
        raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED,
                            detail="unauthorized",
                            headers={"WWW-Authenticate": "Bearer"})
    userFound = [x for x in db.table["user"] if x["username"] == user.email]
    if len(userFound) > 0:
        raise HTTPException(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY,
                            detail="Duplicated email")
    payload = {}
    payload["id"] = len(db.table["user"])
    payload["username"] = user.email
    payload["hashed_password"] = get_password_hash(user.password)
    payload["address"] = user.address
    payload["contact"] = user.contact
    payload["type"] = "customer"
    payload["important"] = False
    db.table["user"].append(payload)
    db.commit()
    return {"success": True}
Example #13
0
def update_user(user_id,
                user: UserInUpdate,
                current_user: User = Depends(get_current_user)):
    user_id = int(user_id)
    index = next(
        (i
         for i, item in enumerate(db.table["user"]) if item["id"] == user_id),
        -1)
    if index < 0:
        raise HTTPException(status_code=404, detail="Not Found")

    if user.password is not None:
        db.table["user"][index]["hashed_password"] = get_password_hash(
            user.password)
    if user.address is not None:
        db.table["user"][index]["address"] = user.address
    if user.contact is not None:
        db.table["user"][index]["contact"] = user.contact
    if user.type is not None:
        db.table["user"][index]["type"] = user.type
    if user.important is not None:
        db.table["user"][index]["important"] = user.important
    db.commit()
    return {"success": True}