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)
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)