def test_update_dish(self):
        dish = self.add_dish()
        new_dish = Dish.find_by_id(dish.id)

        payload = {
            "cuisine": 99,
            "prep_hour": 99,
            "prep_minute": 99,
            "cook_hour": 99,
            "cook_minute": 99,
            "course": 99,
            "dish_name": "Test Me!",
            "serving_count": 99
        }

        new_dish.update(payload)

        updated_dish = Dish.find_by_id(dish.id)

        self.assertEqual(99, updated_dish.cook_minute)
        self.assertEqual(99, updated_dish.cuisine)
        self.assertEqual(99, updated_dish.prep_hour)
        self.assertEqual(99, updated_dish.prep_minute)
        self.assertEqual(99, updated_dish.cook_hour)
        self.assertEqual(99, updated_dish.course)
        self.assertEqual("Test Me!", updated_dish.dish_name)
        self.assertEqual(99, updated_dish.serving_count)
        self.assertEqual(1, updated_dish.status)
Exemple #2
0
    def __init__(self, type_of_menu=TypeOfMenu.STANDARD_MENU, currency="", price=0, name="",
                 temperature=Temperature.NORMAL, weigh=0, level_of_spicy=LevelOfSpicy.NORMAL,
                 type_of_noodles=TypeOfNoodles.SOBA, type_of_meat=TypeOfMeat.BEEF,
                 type_of_sauce=TypeOfSauce.SOUR_SWEET):
        Dish.__init__(self, type_of_menu, currency, price, name,
                      temperature, weigh, level_of_spicy)

        self.type_of_noodles = type_of_noodles
        self.type_of_meat = type_of_meat
        self.type_of_sauce = type_of_sauce
Exemple #3
0
    def __init__(self,
                 type_of_menu=TypeOfMenu.STANDARD_MENU,
                 currency="",
                 price=0,
                 name="",
                 temperature=Temperature.NORMAL,
                 weigh=0,
                 level_of_spicy=LevelOfSpicy.NORMAL,
                 number_of_sushi=0):
        Dish.__init__(self, type_of_menu, currency, price, name, temperature,
                      weigh, level_of_spicy)

        self.number_of_sushi = number_of_sushi
Exemple #4
0
    def __init__(self,
                 type_of_menu=TypeOfMenu.STANDARD_MENU,
                 currency="",
                 price=0,
                 name="",
                 temperature=Temperature.NORMAL,
                 weigh=0,
                 level_of_spicy=LevelOfSpicy.NORMAL,
                 size=Size.STANDARD,
                 style_of_dough=StyleOfDough.AMERICAN):
        Dish.__init__(self, type_of_menu, currency, price, name, temperature,
                      weigh, level_of_spicy)

        self.size = size
        self.style_of_dough = style_of_dough
Exemple #5
0
    def post(self):
        t0 = time.time()

        page = 1
        size = 1000
        count = 0
        hasData = True

        while hasData:
            dishes = Dish.get_dish_import(page=page, size=size)

            if len(dishes.items) == 0:
                hasData = False
            else:
                es.bulk_index(body=dishes.items)
                count += len(dishes.items)
                page += 1

        t1 = time.time()
        elapse = t1 - t0

        list = {
            "totalDataIndexed": count,
            "time": elapse,
            "totalPagesIndexed": page
        }

        return dict(list=list), 200
Exemple #6
0
    def post(self):
        if not get_jwt_identity():
            return dict(code=CODE_UNAUTHORIZED, message=UNAUTHORIZED_ERROR, errors=['Invalid token. Please try again.']), 401

        req = request.get_json(force=True)
        errors = IngredientNewSerializer().validate(req)

        if errors:
            return dict(code=CODE_BAD_REQUEST, message=BAD_REQUEST, errors=errors), 400

        try:
            ins = Ingredients.find_last_step(req['dish_id'])
            step_order = 1 if ins is None else ins.step_order + 1

            ingredient = Ingredients(**req)
            ingredient.step_order = step_order
            ingredient.grocery_item_id = 1 # Set as default 1 for now
            ingredient.main_dish = 1 # Set as default 1 for now
            ingredient.status = 1 # Active as default
            ingredient.save()

            # trigger update for es_keywords field on dish
            dish = Dish.find_by_id(req['dish_id'])
            dish.update_es_keywords()

            # index document
            es.index_document(id=req['dish_id'], body=DishSchema().dump(ingredient.dish))

            return dict(message="OK", data=IngredientSchema().dump(ingredient)), 200
        except Exception as e:
            logging.debug(f"[err] update ingredient - {e} => {req}")
            return dict(message=INTERNAL_ERROR, errors=['An error occured. Please try again later.']), 400
Exemple #7
0
def select(dish_id):
    sql = "SELECT * FROM dishes WHERE id = %s"
    values = [dish_id]
    result = run_sql(sql, values)[0]
    dish = Dish(result['name'], result['price'], result['description'],
                result['restaurant_id'], result['id'])
    return dish
Exemple #8
0
    def put(self, ingr_id):
        if not get_jwt_identity():
            return dict(code=CODE_UNAUTHORIZED, message=UNAUTHORIZED_ERROR, errors=['Invalid token. Please try again.']), 401

        req = request.get_json(force=True)
        errors = IngredientUpdateSerializer().validate(req)

        if errors:
            return dict(code=CODE_BAD_REQUEST, message=BAD_REQUEST, errors=errors), 400

        try:
            ingredient = Ingredients.find_by_id(ingr_id)

            if not ingredient:
                return dict(code=CODE_BAD_REQUEST, message=BAD_REQUEST, errors=['Ingredient not found.']), 400

            ingredient.update(req)

            # trigger update for es_keywords field on dish
            dish = Dish.find_by_id(ingredient.dish.id)
            dish.update_es_keywords()

            # index document
            es.index_document(id=ingredient.dish.id, body=DishSchema().dump(ingredient.dish))

            return dict(message="OK", data=IngredientSchema().dump(ingredient)), 200
        except Exception as e:
            # log the error here
            return dict(message=INTERNAL_ERROR, errors=['An error occured. Please try again later.']), 400
Exemple #9
0
    def put(self, dish_id):
        if not get_jwt_identity():
            return dict(code=CODE_UNAUTHORIZED,
                        message=UNAUTHORIZED_ERROR,
                        errors={"message": "Invalid credentials."}), 401

        req = request.get_json(force=True)
        errors = DishUpdateSerializer().validate(req)

        if errors:
            return dict(code=CODE_BAD_REQUEST,
                        message=BAD_REQUEST,
                        errors=errors), 400

        dish = Dish.find_by_id(dish_id)

        if not dish:
            return dict(code=CODE_BAD_REQUEST,
                        message=BAD_REQUEST,
                        errors=['Dish not found.']), 400

        dish.update(req)
        es.index_document(id=dish.id, body=DishSchema().dump(dish))

        return dict(message="OK", data=DishSchema().dump(dish)), 200
Exemple #10
0
    def test_add_dish_missing_user(self):
        payload = {
            "cook_minute": 10,
            "cuisine": 1,
            "prep_hour": 0,
            "prep_minute": 10,
            "cook_hour": 3,
            "course": 1,
            "dish_name": "Chicken Bulanglang",
            "serving_count": 4
        }

        dish = Dish(**payload)
        dish.save()

        self.assertEqual(1, dish.id)
Exemple #11
0
    def __init__(self,
                 type_of_menu=TypeOfMenu.STANDARD_MENU,
                 currency="",
                 price=0,
                 name="",
                 temperature=Temperature.NORMAL,
                 weigh=0,
                 level_of_spicy=LevelOfSpicy.NORMAL,
                 capacity=0,
                 presence_of_caffeine=False,
                 presence_of_lactose=True):
        Dish.__init__(self, type_of_menu, currency, price, name, temperature,
                      weigh, level_of_spicy)

        self.capacity = capacity
        self.presence_of_caffeine = presence_of_caffeine
        self.presence_of_lactose = presence_of_lactose
Exemple #12
0
    def add_dish(self):
        user = self.register_user()

        payload = {
            "cook_minute": 10,
            "cuisine": 1,
            "prep_hour": 0,
            "prep_minute": 10,
            "cook_hour": 3,
            "course": 1,
            "dish_name": "Chicken Bulanglang",
            "serving_count": 4,
            "user_id": 1
        }

        dish = Dish(**payload)
        dish.save()

        return dish
Exemple #13
0
def update_dish(id):
    name = request.form["name"]
    price = request.form["price"]
    description = request.form["description"]
    restaurant_id = request.form["restaurant"]

    restaurant = restaurant_repository.select(restaurant_id)

    update_dish = Dish(name, price, description, restaurant, id)
    dish_repository.update(update_dish)
    return redirect("/dishes")
Exemple #14
0
def create_dish():
    name = request.form["name"]
    price = request.form["price"]
    description = request.form["description"]
    restaurant_id = request.form['restaurant']

    restaurant = restaurant_repository.select(restaurant_id)

    new_dish = Dish(name, price, description, restaurant)

    dish_repository.save(new_dish)
    return redirect('/dishes')
Exemple #15
0
def select_all():
    dishes = []

    sql = "SELECT * FROM dishes"
    results = run_sql(sql)

    for result in results:
        restaurant = restaurant_repository.select(result['restaurant_id'])
        dish = Dish(result['name'], result['price'], result['description'],
                    restaurant, result['id'])
        dishes.append(dish)
    return dishes
Exemple #16
0
    def post(self):
        if not get_jwt_identity():
            return dict(code=CODE_UNAUTHORIZED,
                        message=UNAUTHORIZED_ERROR,
                        errors={"message": "Invalid credentials."}), 401

        req = request.get_json(force=True)
        errors = DishNewSerializer().validate(req)

        if errors:
            return dict(code=CODE_BAD_REQUEST,
                        message=BAD_REQUEST,
                        errors=errors), 400

        dish = Dish(**req)
        dish.save()

        # index document
        obj = Dish.find_by_id(dish.id)
        es.create(id=obj.id, body=DishSchema().dump(obj))

        return dict(message="OK", data=DishSchema().dump(dish)), 200
Exemple #17
0
    def post(self):
        # trigger update for es_keywords field on dish
        try:
            page = 1
            size = 1000
            dishes = Dish.get_dish_import(page=page, size=size)

            for d in dishes.items:
                d.update_es_keywords()

            return dict(message="Successful"), 200

        except Exception as e:
            logging.debug(f"[err] Sync es keywords => {e}")
Exemple #18
0
    def test_add_dish(self):
        dish = self.add_dish()
        new_dish = Dish.find_by_id(dish.id)

        self.assertEqual(dish.id, new_dish.id)
        self.assertEqual(dish.dish_name, new_dish.dish_name)
        self.assertEqual(dish.cook_minute, new_dish.cook_minute)
        self.assertEqual(dish.cuisine, new_dish.cuisine)
        self.assertEqual(dish.prep_hour, new_dish.prep_hour)
        self.assertEqual(dish.cook_hour, new_dish.cook_hour)
        self.assertEqual(dish.course, new_dish.course)
        self.assertEqual(dish.cook_hour, new_dish.cook_hour)
        self.assertEqual(dish.serving_count, new_dish.serving_count)
        self.assertEqual(dish.user_id, new_dish.user_id)
        self.assertEqual(dish.status, new_dish.status)
Exemple #19
0
    def get(self, dish_id):
        if not get_jwt_identity():
            return dict(code=CODE_UNAUTHORIZED,
                        message=UNAUTHORIZED_ERROR,
                        errors={"message": "Invalid credentials."}), 401

        data = Dish.find_by_id(dish_id)

        # res = Collection(data.ingredients).get_active()
        # app.logger.info(res)

        schema = DishSchema().dump(data)

        # schema['ingredients'] = list(map(
        #     lambda ingr: ingr,
        #     filter(lambda i: i['status'] == 1, schema['ingredients'])
        # ))

        return dict(message="OK", data=schema), 200
Exemple #20
0
    def post(self, dish_id):
        if not get_jwt_identity():
            return dict(code=CODE_UNAUTHORIZED,
                        message=UNAUTHORIZED_ERROR,
                        errors={"message": "Invalid credentials."}), 401

        dish = Dish.find_by_id(dish_id)

        if not dish:
            return dict(code=CODE_BAD_REQUEST,
                        message=BAD_REQUEST,
                        errors=['Dish not found.']), 200

        dish.status = 0
        dish.save()

        # index dish
        es.index_document(id=dish.id, body=DishSchema().dump(dish))

        return dict(message="Successfully deleted."), 200
Exemple #21
0
    def post(self, ingr_id):
        if not get_jwt_identity():
            return dict(code=CODE_UNAUTHORIZED, message=UNAUTHORIZED_ERROR, errors=['Invalid token. Please try again.']), 401

        ingredient = Ingredients.find_by_id(ingr_id)

        if not ingredient:
            return dict(code=CODE_BAD_REQUEST, message=BAD_REQUEST, errors=['Ingredient not found.']), 400

        ingredient.status = 0
        ingredient.save()

        # trigger update for es_keywords field on dish
        dish = Dish.find_by_id(ingredient.dish.id)
        dish.update_es_keywords()

        # index document
        es.index_document(id=ingredient.dish.id, body=DishSchema().dump(ingredient.dish))

        return dict(message="Successfully deleted."), 200
Exemple #22
0
    def get(self):
        if not get_jwt_identity():
            return dict(code=CODE_UNAUTHORIZED,
                        message=UNAUTHORIZED_ERROR,
                        errors={"message": "Invalid credentials."}), 401

        req = request.args
        errors = PaginationQSValidator().validate(req)

        if errors:
            return dict(code=CODE_BAD_REQUEST,
                        message=BAD_REQUEST,
                        errors=errors), 400

        dish = Dish.get_all_dishes(**req)
        list = {
            "list": DishSchema(many=True).dump(dish.items),
            "count": len(dish.items),
            "total": dish.total
        }

        return dict(message="OK", data=list), 200
Exemple #23
0
 def transform_element_to_dish(cls, dish_element: Tag) -> Dish:
     name = dish_element.find("strong").text
     price = dish_element.find("span", {"class", "food-price"}).text
     description = dish_element.find("span", {"class", "food-alergens"}).text
     return Dish(name, price, description)
Exemple #24
0
 def __str__(self):
     return str(Dish.__str__(self)) + "\nnumber_of_sushi = " + str(
         self.number_of_sushi)
Exemple #25
0
customer_repository.save(customer1)

chinese = Cuisine("Chinese")
cuisine_repository.save(chinese)
japanese = Cuisine("Japanese")
cuisine_repository.save(japanese)
fast_food = Cuisine("Fast Food")
cuisine_repository.save(fast_food)

mcdonalds = Restaurant("McDonalds", "137 Princes St", "01312263872", True,
                       fast_food)
restaurant_repository.save(mcdonalds)
kfc = Restaurant("KFC", "36 Nicolson St", "01316629524", True, fast_food)
restaurant_repository.save(kfc)

cheeseburger = Dish("Cheeseburger", 0.99, "A burger with cheese", mcdonalds)
dish_repository.save(cheeseburger)
doublecheeseburger = Dish("Double Cheeseburger", 1.99,
                          "A double burger with cheese", mcdonalds)
dish_repository.save(doublecheeseburger)
triplecheeseburger = Dish("Triple Cheeseburger", 2.99,
                          "A triple burger with cheese", mcdonalds)
dish_repository.save(triplecheeseburger)
quarterpounder = Dish("Quarter Pounder", 1.99,
                      "A burger that is a quarter of a pound", mcdonalds)
dish_repository.save(quarterpounder)
chickenlegend = Dish("Chicken Legend", 1.99, "A chicken burger", mcdonalds)
dish_repository.save(chickenlegend)

hotwings = Dish("Hot Wing", 0.50, "Hot and spicy chicken wings", kfc)
dish_repository.save(hotwings)
Exemple #26
0
 def __str__(self):
     return str(Dish.__str__(self)) + "\nsize = " + str(
         self.size) + "\nstyle_of_dough = " + str(self.style_of_dough)
Exemple #27
0
from models.dish import Dish
from models.pizza import Pizza
from models.sushi import Sushi
from models.wok import Wok
from enums.type_of_menu import TypeOfMenu
from enums.temperature import Temperature
from enums.type_of_meat import TypeOfMeat
from enums.style_of_dough import StyleOfDough
from enums.size import Size
from enums.level_of_spicy import LevelOfSpicy
from enums.type_of_sauce import TypeOfSauce
from enums.type_of_noodles import TypeOfNoodles
from managers.dish_manager import DishManager

dishes = [
    Dish(TypeOfMenu.CHILD_MENU, "$", 25, "Puree", Temperature.NORMAL, 200,
         LevelOfSpicy.NOT_SPICY),
    Drinks(TypeOfMenu.VEGETARIAN_MENU, "$", 15, "Milk", Temperature.COLD, 300,
           LevelOfSpicy.NOT_SPICY, 300, False, True),
    Pizza(TypeOfMenu.STANDARD_MENU, "$", 150, "Paperoni", Temperature.HOT, 500,
          LevelOfSpicy.NORMAL, Size.STANDARD, StyleOfDough.AMERICAN),
    Sushi(TypeOfMenu.STANDARD_MENU, "$", 55, "California", Temperature.COLD,
          300, LevelOfSpicy.NOT_SPICY, 6),
    Wok(TypeOfMenu.STANDARD_MENU, "$", 35, "CCC", Temperature.HOT, 300,
        LevelOfSpicy.HIGH, TypeOfNoodles.SOBA, TypeOfMeat.BEEF,
        TypeOfSauce.SOUR_SWEET)
]

dish_manager = DishManager(*dishes)
for i in dishes:
    print()
    print(i)
Exemple #28
0
 def __str__(self):
     return str(Dish.__str__(self)) + "\ncapacity = " + str(self.capacity) + "\npresence_of_caffeine = "\
            + str(self.presence_of_caffeine) + "\npresence_of_lactose = " + str(self.presence_of_lactose)
Exemple #29
0
 def __str__(self):
     return str(Dish.__str__(self)) + "\ntype_of_noodles = " + str(self.type_of_noodles) + "\ntype_of_meat = "\
            + str(self.type_of_meat) + "\ntype_of_sauce = " + str(self.type_of_sauce)