def add_meal(body): # noqa: E501 """Add meal This can only be done by the logged in user. # noqa: E501 :param body: Meal object to Add :type body: dict | bytes :rtype: None """ if connexion.request.is_json: body = Meal.from_dict(connexion.request.get_json()) # noqa: E501 if(body.food_name in meals): return "Meal already in the list" if(not body.meal_id): #find meal_id body.meal_id=str(uuid.uuid4()) try: if(not body.calorie): body.calorie=int(Nutrionix.nutrionix_calorie(body.food_name)) except Exception as e: print("API errror occured with an error"+str(e)) mealid_body[body.meal_id]=body meals.append(body.food_name) print(mealid_body) return "Added meal with id:"+body.meal_id
def add_meal(username, body): # noqa: E501 """Add meal # noqa: E501 :param username: :type username: str :param body: Meal object to add :type body: dict | bytes :rtype: None """ if connexion.request.is_json: body = Meal.from_dict(connexion.request.get_json()) # noqa: E501 uid = unique_id() UC.user_meal_map[username][1][uid] = body print(UC.user_meal_map) return uid
def update_meal(meal_id, body): # noqa: E501 """Update Meal entry This can only be done by the logged in user. # noqa: E501 :param meal_id: meal that needs to be updated :type meal_id: str :param body: Updated meal object :type body: dict | bytes :rtype: None """ meal_id = int(meal_id) if meal_id not in meals: msg = 'Meal not found!' return make_response(msg, 404) if connexion.request.is_json: body = Meal.from_dict(connexion.request.get_json()) # noqa: E501 # Check for the match b/w meal_id and body.meal_id if meal_id != body.meal_id: msg = "No match between Meal ids!" return make_response(msg, 400) # if body doesn't have calories as input try: if not body.calorie: body.calorie = int(Nutrionix.fetch_calories(body.food_name)) except Exception as e: print("Failed to reach Nutrionix: " + str(e)) body.calorie = 0 meals[meal_id] = body desc = f'Successfully updated meal with Meal id: {meal_id}' response = {'message': desc, "updated_meal": body} return jsonify(response)
def update_meal(meal_id, body): # noqa: E501 """Update Meal entry This can only be done by the logged in user. # noqa: E501 :param meal_id: meal that needs to be updated :type meal_id: str :param body: Updated meal object :type body: dict | bytes :rtype: None """ if connexion.request.is_json: body = Meal.from_dict(connexion.request.get_json()) # noqa: E501 if(meal_id not in mealid_body): return make_response("Invalid meal",400) else: mealid_body[meal_id]=body return 'updated meal'
def update_meal(mealId, username, body): # noqa: E501 """Update Meal entry This can only be done by the logged in user. # noqa: E501 :param mealId: meal that needs to be updated :type mealId: str :param username: :type username: str :param body: Updated meal object :type body: dict | bytes :rtype: None """ if connexion.request.is_json: body = Meal.from_dict(connexion.request.get_json()) # noqa: E501 del (UC.user_meal_map[username][1][mealId]) UC.user_meal_map[username][1][mealId] = body print(UC.user_meal_map) return 'meal updated'
def add_meal(body): # noqa: E501 """Add meal This can only be done by the logged in user. # noqa: E501 :param body: Meal object to Add :type body: dict | bytes :rtype: None """ if connexion.request.is_json: body = Meal.from_dict(connexion.request.get_json()) # noqa: E501 try: if not body.calorie: body.calorie = int(Nutrionix.fetch_calories(body.food_name)) except Exception as e: print("Failed to reach Nutrionix: " + str(e)) body.calorie = 0 meals[body.meal_id] = body return body