Esempio n. 1
0
def create_cuisine():
    user = User.get_by_id(get_jwt_identity())
    if user.is_admin:
        name = request.json.get("name")
        if name == "":
            return error
        cuisine = Cuisine(name=name)
        if cuisine.save():
            return jsonify({
                "successful": True,
                "message": name + " cuisine is created successfully"
            })

    else:
        return jsonify(
            {"errors": "Non-admin user detected. Request cannot be done."})
Esempio n. 2
0
def show_recipe_step(cuisine_name, recipe_name, step_number):
    cuisine = Cuisine.get_or_none(name=cuisine_name)

    if cuisine:
        recipe = Recipe.get_or_none(name=recipe_name)
        if recipe:
            if recipe.cuisine_id == cuisine.id:
                step = Step.select().where(Step.recipe_id == recipe.id,
                                           Step.number == step_number)
                for s in step:
                    result = {
                        "step_number": s.number,
                        "description": s.description
                    }
                return jsonify({"data": result})
            else:
                return jsonify({
                    "errors":
                    recipe_name + " is not found in " + cuisine_name +
                    " cuisine."
                })
        else:
            return jsonify({"errors": "Recipe not exists"})
    else:
        return jsonify({"errors": cuisine_name + " cusine is not exist"})
Esempio n. 3
0
def add_recipe_ingredient(cuisine_name, recipe_name):
    current_user = User.get_by_id(get_jwt_identity())

    if current_user.is_admin:
        cuisine = Cuisine.get_or_none(name=cuisine_name)
        if cuisine:
            recipe = Recipe.get_or_none(name=recipe_name)
            if recipe:
                if recipe.cuisine_id == cuisine.id:
                    quantity = request.form.get("quantity")
                    name = request.form.get("name")
                    recipe_ingredient = RecipeIngredient(name=name,
                                                         quantity=quantity,
                                                         recipe_id=recipe.id)
                    recipe_ingredient.save()
                    return jsonify({
                        "message":
                        "Ingredient has been successfully created!"
                    })
                else:
                    return jsonify({
                        "errors":
                        recipe_name + " is not found in " + cuisine_name +
                        " cuisine."
                    })
            else:
                return jsonify({"errors": "Recipe not exists"})
        else:
            return jsonify({"errors": cuisine_name + " cusine is not exist"})
    else:
        return 0
Esempio n. 4
0
def delete_recipe_ingredient(cuisine_name, recipe_name):
    current_user = User.get_by_id(get_jwt_identity())

    if current_user.is_admin:
        cuisine = Cuisine.get_or_none(name=cuisine_name)
        if cuisine:
            recipe = Recipe.get_or_none(name=recipe_name)
            if recipe:
                if recipe.cuisine_id == cuisine.id:
                    name = request.form.get("name")
                    delete = RecipeIngredient.delete().where(
                        RecipeIngredient.name == name,
                        RecipeIngredient.recipe_id == recipe.id)
                    delete.execute()
                    return jsonify({
                        "message":
                        "Ingredient has been successfully deleted!"
                    })
                else:
                    return jsonify({
                        "errors":
                        recipe_name + " is not found in " + cuisine_name +
                        " cuisine."
                    })
            else:
                return jsonify({"errors": "Recipe not exists"})
        else:
            return jsonify({"errors": cuisine_name + " cusine is not exist"})
    else:
        return 0
Esempio n. 5
0
def delete_cuisine_recipe(cuisine_name):
    user = User.get_by_id(get_jwt_identity())

    if user.is_admin:
        cuisine = Cuisine.get_or_none(name=cuisine_name)

        if cuisine:
            name = request.json.get("recipe_name")
            recipe = Recipe.get(name=name)

            if recipe.cuisine_id == cuisine.id:
                recipe.delete_instance()
                return jsonify({
                    "message":
                    recipe.name + " has been successfully deleted from " +
                    cuisine_name + " cuisine."
                })
            else:
                return jsonify({
                    "errors":
                    recipe.name + " is not found in " + cuisine_name +
                    " cuisine."
                })
        else:
            return jsonify({"errors": cuisine_name + " cuisine is not exist"})
    else:
        return jsonify(
            {"errors": "Non-admin user deteced. Request cannot be done."})
Esempio n. 6
0
def show_cuisine_single_recipe(cuisine_name, recipe_name):
    cuisine = Cuisine.get_or_none(name=cuisine_name)

    if cuisine:
        is_recipe = Recipe.get_or_none(name=recipe_name)

        if is_recipe:
            recipe = Recipe.select().where(Recipe.cuisine_id == cuisine.id,
                                           Recipe.name == recipe_name)
            if recipe:
                for r in recipe:
                    result = {
                        "name": r.name,
                        "image": r.image,
                        "difficulty": r.difficulty
                    }
                return jsonify({"data": result})
            else:
                return jsonify({
                    "erros":
                    recipe_name + " is not found in " + cuisine_name +
                    " cuisine."
                })
        else:
            return jsonify({"errors": "Recipe not exists"})
    else:
        return jsonify({"errors": cuisine_name + " cuisine is not exist"})
Esempio n. 7
0
def show_cuisine():
    cuisine_all = Cuisine.select()

    results = []
    for cuisine in cuisine_all:
        cuisine_data = {"name": cuisine.name}
        results.append(cuisine_data)
    return jsonify({"data": results})
Esempio n. 8
0
def select_all():
    cuisines = []
    sql = "SELECT * FROM cuisines"
    results = run_sql(sql)
    for result in results:
        cuisine = Cuisine(result['cuisine'], result['id'])
        cuisines.append(cuisine)
    return cuisines
Esempio n. 9
0
def update_cuisine_recipe(cuisine_name):
    user = User.get_by_id(get_jwt_identity())

    if user.is_admin:
        cuisine = Cuisine.get_or_none(name=cuisine_name)

        if cuisine:
            update_field = request.form.get("update_field")

            if update_field == "name":
                name = request.form.get("recipe_name")
                recipe = Recipe.get(name=name)
                update_content = request.form.get("update_content")
                update = Recipe.update(name=update_content).where(
                    Recipe.id == recipe.id)
                update.execute()
                return jsonify(
                    {"message": "Name has been successfully updated"})
            elif update_field == "difficulty":
                name = request.form.get("recipe_name")
                recipe = Recipe.get(name=name)
                update_content = request.form.get("update_content")
                update = Recipe.update(difficulty=update_content).where(
                    Recipe.id == recipe.id)
                update.execute()
                return jsonify(
                    {"message": "Difficulty has been successfully updated"})
            elif update_field == "image":
                name = request.form.get("recipe_name")
                recipe = Recipe.get(name=name)
                file = request.files.get("image")
                bucket_name = os.getenv('AWS_S3_BUCKET')
                s3.upload_fileobj(file,
                                  bucket_name,
                                  file.filename,
                                  ExtraArgs={
                                      "ACL": "public-read",
                                      "ContentType": file.content_type
                                  })
                update = Recipe.update(
                    image=
                    f'https://kevinchan950-nextagram-flask.s3-ap-southeast-1.amazonaws.com/{file.filename}'
                ).where(Recipe.id == recipe.id)
                update.execute()
                return jsonify(
                    {"message": "Image has been successfully updated"})
            else:
                return error
        else:
            return jsonify({"errors": cuisine_name + " cuisine is not exist"})
    else:
        return jsonify(
            {"errors": "Non-admin user deteced. Request cannot be done."})
Esempio n. 10
0
def delete_cuisine():
    user = User.get_by_id(get_jwt_identity())
    if user.is_admin:
        name = request.json.get("name")
        cuisine = Cuisine.get(name=name)
        cuisine.delete_instance()
        return jsonify({
            "message":
            cuisine.name + " cuisine has been successfully deleted!"
        })
    else:
        return jsonify(
            {"errors": "Non-admin user detected. Request cannot be done."})
Esempio n. 11
0
def update_cuisine():
    user = User.get_by_id(get_jwt_identity())
    if user.is_admin:
        name = request.json.get("name")
        new_name = request.json.get("new_name")
        print(name)
        print(new_name)
        update = Cuisine.update(name=new_name).where(Cuisine.name == name)
        update.execute()
        return jsonify({"message": "Name has been successfully updated!"})
    else:
        return jsonify(
            {"errors": "Non-admin user detected. Request cannot be done."})
Esempio n. 12
0
def show_cuisine_recipe(cuisine_name):
    cuisine = Cuisine.get_or_none(name=cuisine_name)

    if cuisine:
        recipe_all = Recipe.select().where(Recipe.cuisine_id == cuisine.id)
        results = []
        for recipe in recipe_all:
            recipe_data = {
                "name": recipe.name,
                "image": recipe.image,
                "difficulty": recipe.difficulty
            }
            results.append(recipe_data)
        return jsonify({"data": results})
    else:
        return jsonify({"errors": cuisine_name + " cuisine is not exist"})
Esempio n. 13
0
def delete_recipe_step(cuisine_name, recipe_name):
    user = User.get_by_id(get_jwt_identity())
    cuisine = Cuisine.get_or_none(name=cuisine_name)
    if user.is_admin:
        if cuisine:
            recipe = Recipe.get_or_none(name=recipe_name)
            if recipe:
                step_number = request.form.get("step_number")
                delete = Step.delete().where(Step.number == step_number,
                                             Step.recipe_id == recipe.id)
                delete.execute()
                return jsonify(
                    {"message": "Step has been successfully deleted."})
            else:
                return jsonify({"errors": "Recipe not exists"})
        else:
            return jsonify({"errors": cuisine_name + " cusine is not exist"})
    else:
        return 0
Esempio n. 14
0
def new_recipe_step(cuisine_name, recipe_name):
    user = User.get_by_id(get_jwt_identity())
    cuisine = Cuisine.get_or_none(name=cuisine_name)
    if user.is_admin:
        if cuisine:
            recipe = Recipe.get_or_none(name=recipe_name)
            if recipe:
                step_number = request.form.get("step_number")
                step_description = request.form.get("step_description")
                new_step = Step(number=step_number,
                                description=step_description,
                                recipe_id=recipe.id)
                new_step.save()
                return jsonify({"message": "Step successfully created!"})
            else:
                return jsonify({"errors": "Recipe not exists"})
        else:
            return jsonify({"errors": cuisine_name + " cusine is not exist"})
    else:
        return 0
Esempio n. 15
0
def show_recipe_all_step(cuisine_name, recipe_name):
    cuisine = Cuisine.get_or_none(name=cuisine_name)
    if cuisine:
        recipe = Recipe.get_or_none(name=recipe_name)
        if recipe:
            step_all = Step.select().where(Step.recipe_id == recipe.id)
            results = []
            for step in step_all:
                step_data = {
                    "step_number": step.number,
                    "step_description": step.description
                }
                results.append(step_data)
            return jsonify({"data": results})
        else:
            return jsonify({
                "errors":
                recipe_name + " is not found in " + cuisine_name + " cuisine."
            })
    else:
        return jsonify({"errors": cuisine_name + " cusine is not exist"})
Esempio n. 16
0
def create_cuisine_recipe(cuisine_name):
    user = User.get_by_id(get_jwt_identity())

    if user.is_admin:
        cuisine = Cuisine.get_or_none(name=cuisine_name)

        if cuisine:
            file = request.files.get('image')
            name = request.form.get("recipe_name")
            bucket_name = os.getenv('AWS_S3_BUCKET')
            s3.upload_fileobj(file,
                              bucket_name,
                              file.filename,
                              ExtraArgs={
                                  "ACL": "public-read",
                                  "ContentType": file.content_type
                              })
            difficulty = request.form.get("recipe_difficulty")
            recipe = Recipe(
                name=name,
                image=
                f'https://kevinchan950-nextagram-flask.s3-ap-southeast-1.amazonaws.com/{file.filename}',
                difficulty=difficulty,
                cuisine_id=cuisine.id)

            if recipe.save():
                return jsonify({
                    "successful":
                    True,
                    "message":
                    name + " has been successfully created for " +
                    cuisine_name + " cuisine."
                })
        else:
            return jsonify({"errors": cuisine_name + " cuisine is not exist"})
    else:
        return jsonify(
            {"errors": "Non-admin user detected. Request cannot be done."})
Esempio n. 17
0
def show_recipe_ingredient(cuisine_name, recipe_name):
    cuisine = Cuisine.get_or_none(name=cuisine_name)

    if cuisine:
        recipe = Recipe.get_or_none(name=recipe_name)
        if recipe:
            if recipe.cuisine_id == cuisine.id:
                ingredient = RecipeIngredient.select().where(
                    RecipeIngredient.recipe_id == recipe.id)
                results = []
                for i in ingredient:
                    ingredient_data = {"name": i.name, "quantity": i.quantity}
                    results.append(ingredient_data)
                return jsonify({"data": results})
            else:
                return jsonify({
                    "errors":
                    recipe_name + " is not found in " + cuisine_name +
                    " cuisine."
                })
        else:
            return jsonify({"errors": "Recipe not exists"})
    else:
        return jsonify({"errors": cuisine_name + " cusine is not exist"})
Esempio n. 18
0
def update_cuisines(id):
    cuisine = request.form["cuisine"]
    update_cuisine = Cuisine(cuisine, id)
    cuisine_repository.update(update_cuisine)
    return redirect("/cuisines")
Esempio n. 19
0
def select(id):
    sql = "SELECT * FROM cuisines WHERE id = %s"
    values = [id]
    result = run_sql(sql, values)[0]
    cuisine = Cuisine(result['cuisine'], result['id'])
    return cuisine
Esempio n. 20
0
order_dish_repository.delete_all()
customer_repository.delete_all()
cuisine_repository.delete_all()
restaurant_repository.delete_all()
order_repository.delete_all()
dish_repository.delete_all()

customer1 = Customer("Jenken", "1 Street Name", "Card", "07123456789",
                     "Delivery")
customer_repository.save(customer1)
customer1 = Customer("Jenken2", "2 Street Name", "Card", "07123456789",
                     "Delivery")
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,
Esempio n. 21
0
def create_cuisines():
    cuisine = request.form['cuisine']
    new_cuisine = Cuisine(cuisine)
    cuisine_repository.save(new_cuisine)
    return redirect("/cuisines")
Esempio n. 22
0
        'password_confirmation': 'pass'
    })
    cath, errors = user_schema.load({
        'username': '******',
        'email': 'cath@email',
        'password': '******',
        'password_confirmation': 'pass'
    })
    david, errors = user_schema.load({
        'username': '******',
        'email': 'david@email',
        'password': '******',
        'password_confirmation': 'pass'
    })

    french = Cuisine(name='French')
    thai = Cuisine(name='Thai')
    indonesian = Cuisine(name='Indonesian')
    chinese = Cuisine(name='Chinese')
    turkish = Cuisine(name='Turkish')
    italian = Cuisine(name='Italian')
    fusion = Cuisine(name='Fusion')
    moroccan = Cuisine(name='Moroccan')

    quick = Tag(name='Quick')
    student = Tag(name='Student')
    budget = Tag(name='Budget')
    family = Tag(name='Family')
    seasonal = Tag(name='Seasonal')
    summer = Tag(name='Summer')
    winter = Tag(name='Winter')
Esempio n. 23
0
            session3.add(record)

        data3 = Load_Data_3("csv/1time.csv")
        for i in data3:
            record = Time(**{'id': i[0], 'minutes': i[1]})
            session3.add(record)

        data4 = Load_Data_1("csv/1categories.csv")
        for i in data4:
            record = Categories(**{'id': i[0], 'category_name': i[1]})
            session3.add(record)

        data5 = Load_Data_1("csv/1cuisine.csv")
        for i in data5:
            record = Cuisine(**{'id': i[0], 'cuisine_name': i[1]})
            session3.add(record)

        data6 = Load_Data_1("csv/1menu.csv")
        for i in data6:
            record = Menu(**{'id': i[0], 'menu_name': i[1]})
            session3.add(record)

        data7 = Load_Data_3("csv/1recipe_has_ingredients.csv")
        for i in data7:
            record = Recipe_has_ingredients(**{
                'recipe_id': i[0],
                'ingredients_id': i[1]
            })
            session3.add(record)