예제 #1
0
def create():
    data = request.json

    name = data.get('name')
    ingredients = data.get('ingredients')
    prep_time = data.get('prep_time')
    cookware = data.get('cookware')

    if name and ingredients and prep_time:
        meal = Meal(name=name,
                    ingredients=ingredients,
                    prep_time=prep_time,
                    cookware=cookware)
        if meal.save():
            return jsonify({
                "message": "Successfully created the meal!",
                "status": "success",
                "meal": {
                    "id": meal.id,
                    "name": meal.name
                }
            })
        elif meal.errors != 0:
            return jsonify({
                "message": [error for error in meal.errors],
                "status": "failed"
            })
    else:
        return jsonify({
            "message": "All fields are required!",
            "status": "failed"
        })
def add_a_meal():
    """A Method to add a meal to the system"""
    name = str(request.get_json().get('name'))
    price = str(request.get_json().get('price'))

    if len(name) <= 0 and len(price) <= 0:
        return Meal.bad_request()
    meal = Meal.add_meal(name=name, price=price)
    print(meal)
    if not meal:
        return Meal.bad_request()
    return Meal.meal_created_response()
예제 #3
0
def create():

    resp = request.get_json()
    meal = resp.get('meal')
    food = resp.get('food')
    calories = resp.get('calories')

    meal = Meal(meal=meal, food=food, calories=calories)

    if meal.save():
        message = {'status': True, 'message': 'created'}
    else:
        message = {'status': False, 'message': user.errors}

    return jsonify(message)
예제 #4
0
def generate_meals(num_days: int):
    # increment by 1 day
    for i in range(0, num_days):
        meal_day = date.today() + timedelta(days=i)
        quantity = randint(1, 4)
        recipies = Recipe.objects
        random_recipe = recipies[randint(0, len(recipies))]
        print(random_recipe.title)

        meal = Meal(date=meal_day,
                    quantity=quantity,
                    note="randomly generated",
                    recipe_id=random_recipe.migros_id,
                    recipe_title=random_recipe.title)

        meal.save()
예제 #5
0
def get_meal(user_id):
    req_data = request.json
    if not req_data:
        abort(400)
    return Meal.get_recommended_meals(user_id, req_data.get('cuisines'),
                                      req_data.get('medical_conditions'),
                                      req_data.get('allergies'))
예제 #6
0
def delete():
    current_user = get_jwt_identity()
    user = User.get_or_none(User.username == current_user)
    resp = request.get_json()
    meal = Meal.get_or_none(Meal.food == resp['food'])
    user_meal = User_Meal.get_or_none((User_Meal.user_id == user.id)
                                      & (User_Meal.meal_id == meal.id))

    if user_meal:
        if user_meal.delete_instance():
            message = {
                'status': True,
                'message': "Successfully deleted from database"
            }
        else:
            message = {
                'status': False,
                'message': "Couldn't remove from database"
            }
    else:
        message = {
            'status': False,
            'message': "The meal submitted is not register with user"
        }

    return jsonify(message)
예제 #7
0
    def post(self):
        # Add new meal to daily mealplan.
        data = json.loads(request.data)
        Meal().new_meal(request.user_id, data["recipe"], data["meal"])

        return json.dumps({'success': True}), 200, {
            'ContentType': 'application/json'
        }
예제 #8
0
def index():
    meals = Meal.select()
    return jsonify([{
        "id": meal.id,
        "name": meal.name,
        "prep_time": meal.prep_time,
        "cookware": meal.cookware
    } for meal in meals])
예제 #9
0
def create_order():
    name = "order"
    value = "{{ meal.id }}"
    {{meal.description}}
    name = "qty"
    type = "number"
    order = Meal()
    meal_repository.save(Meal)
    return redirect('/meals')
예제 #10
0
def new_breakfast():

    food = Meal.select().where(Meal.meal == 'breakfast')
    food_data = []

    for f in food:
        info = {"label": f"{f.food} - {f.calories}kcal", "value": f.food}
        food_data.append(info)

    return jsonify(food_data), 200
예제 #11
0
 def get_daily_meal_nutrients(self):
     # Func to calculate the macro for user's day.
     user_goals = User().get_macro_tracking(request.user_id)
     meal_nutrients = Meal().get_meal_nutrients(request.user_id)
     user_macros = {
         x: float(meal_nutrients[x]) / user_goals[x] * 100
         for x in user_goals
     }
     print user_macros, meal_nutrients
     return user_macros
예제 #12
0
def select_all():

    sql = 'SELECT * FROM meals'
    results = run_sql(sql)
    meals = []
    for dictionary in results:
        meal = Meal(dictionary['name'], dictionary['description'],
                    dictionary['cost_price'], dictionary['selling_price'],
                    dictionary['qty_available'], dictionary['qty_sold'],
                    dictionary['id'])
        meals.append(meal)
    return meals
def modify_meal(meal_id):
    """Method to modify an Meal"""
    name = str(request.get_json().get('name'))
    price = str(request.get_json().get('price'))
    if not (name or price):
        response = jsonify({
                "message":"please add all details."
            })
        response.status_code = 400
        return response

    return Meal.update_meal(meal_id, name, price)
예제 #14
0
def update_meal(id):
    print(request.form)
    name = request.form['name']
    description = request.form['description']
    cost_price = request.form['cost_price']
    selling_price = request.form['selling_price']
    qty_available = request.form['qty_available']
    qty_sold = request.form['qty_sold']
    meal = Meal(name, description, cost_price, selling_price, qty_available, qty_sold, id)
    print(meal)
    meal_repository.update(meal)
    return redirect('/manager')
예제 #15
0
def select(id):
    meal = None
    sql = "SELECT * FROM meals WHERE id = %s"
    values = [id]
    meal_dictionary = run_sql(sql, values)[0]

    if meal_dictionary is not None:
        meal = Meal(meal_dictionary['name'], meal_dictionary['description'],
                    meal_dictionary['cost_price'],
                    meal_dictionary['selling_price'],
                    meal_dictionary['qty_available'],
                    meal_dictionary['qty_sold'], meal_dictionary['id'])
    return meal
예제 #16
0
    def get(self):
        if request.args.get('action') == "remove-meal":
            recipe_id = request.args.get('recipe')
            Meal().remove_meal(request.user_id, recipe_id)
            redirect("/dash", code=302)

        data = {
            "logged_in": True,
            "daily_goals": self.get_daily_meal_nutrients(),
            "meals": self.get_daily_meals(),
            "meal_history": self.get_meal_history(),
            "recommended_meals": self.get_recommended()
        }
        return render_template("dash.html", data=data)
예제 #17
0
def new_meal():
    if request.method == 'GET':
        return render_template('/manager/new_meal.html')

    if request.method == 'POST':   
        name = request.form['name']
        description = request.form['description']
        cost_price = request.form['cost_price']
        selling_price = request.form['selling_price']
        qty_available = request.form['qty_available']
        qty_sold = request.form['qty_sold']
        meal = Meal(name, description, cost_price, selling_price, qty_available, qty_sold)
        print(meal)
        meal_repository.save(meal)
        return redirect('/manager')
예제 #18
0
    def get_meal_history(self):
        # Grabs all past meals for user
        meals = Meal().get_all_past_meals(request.user_id)
        results = []
        meal_list = []
        for meal in meals:
            meal_list.append({
                "name": meal[0],
                "recipeid": meal[1],
                "mealtype": meal[2],
            })
        for meal in meal_list:
            meal["mealtype"] = self.meal_map[str(meal["mealtype"])]
            results.append(meal)

        return results
예제 #19
0
    def get_daily_meals(self):
        # Grabs todays mealplan
        meals = Meal().get_daily_meals(request.user_id)
        meal_list = []
        for meal in meals:
            meal_list.append({
                "name": meal[0],
                "recipeid": meal[1],
                "mealtype": meal[2],
            })
        meal_list = sorted(meal_list, key=lambda k: k["mealtype"])
        results = []
        for meal in meal_list:
            meal["mealtype"] = self.meal_map[str(meal["mealtype"])]
            results.append(meal)

        print results
        return results
예제 #20
0
def create():
    resp = request.get_json()

    current_user = get_jwt_identity()
    user = User.get_or_none(User.username == current_user)

    meal = Meal.get_or_none(Meal.food == resp['food'])

    user_meal = User_Meal(user=user.id, meal=meal)

    if user_meal.save():
        message = {
            'status': True,
            'message': "Recorded meal",
            'info': {
                'name': meal.food,
                'calories': meal.calories
            }
        }
    else:
        message = {'status': False, 'message': "Couldn't saved to database."}

    return jsonify(message)
예제 #21
0
 def get(self, meal_id: str) -> Response:
     output = Meal.objects(id=meal_id)
     return jsonify(output)
def get_meal(meal_id):
    """Method to modify an Meal"""
    return Meal.get_meal(meal_id)
def get_all_meals():
    """This method returns all meals stored in the system"""
    return Meal.all_meals()
def delete_meal(meal_id):
    """Method to modify an Meal"""
    return Meal.delete_meal(meal_id)
예제 #25
0
import pdb
from models.meal import Meal
import repositories.meal_repository as meal_repository

meal_repository.delete_all()

meal1 = Meal("beef_meal", "Beef Meal", 5, 6, 2, 0)
meal2 = Meal("chicken_meal", "Chicken Meal", 5, 6, 0, 0)
meal3 = Meal("fish_meal", "Fish Meal", 7, 8, 5, 0)

meal_repository.save(meal1)
meal_repository.save(meal2)
meal_repository.save(meal3)
예제 #26
0
 def get(self) -> Response:
     output = Meal.objects()
     return jsonify({'result': output})
예제 #27
0
 def post(self) -> Response:
     data = request.get_json()
     post_user = Meal(**data).save()
     return jsonify(post_user)
예제 #28
0
 def put(self, meal_id:str) -> Response:
     data = request.get_json()
     put_user = Meal.objects(id=meal_id).update(**data)
     return jsonify(put_user)
예제 #29
0
 def delete(self, meal_id:str) -> Response:
     delete_user = Meal.objects(id=meal_id).delete()
     return jsonify(delete_user)