def set_meal_plan(data: MealPlan, session: Session = Depends(generate_session)): """ Creates a meal plan database entry """ data.process_meals(session) data.save_to_db(session) return SnackResponse.success("Mealplan Created")
def update_meal_plan(plan_id: str, meal_plan: MealPlan, session: Session = Depends(generate_session)): """ Updates a meal plan based off ID """ meal_plan.process_meals(session) meal_plan.update(session, plan_id) return SnackResponse.info("Mealplan Updated")
def set_meal_plan(data: MealPlan): """ Creates a meal plan database entry """ data.process_meals() data.save_to_db() # raise HTTPException( # status_code=404, # detail=SnackResponse.error("Unable to Create Mealplan See Log"), # ) return SnackResponse.success("Mealplan Created")
async def update_meal_plan(plan_id: str, meal_plan: MealPlan): """ Updates a meal plan based off ID """ try: meal_plan.process_meals() meal_plan.update(plan_id) except: raise HTTPException( status_code=404, detail=SnackResponse.error("Unable to Update Mealplan"), ) return SnackResponse.success("Mealplan Updated")
def get_today(): """ Returns the recipe slug for the meal scheduled for today. If no meal is scheduled nothing is returned """ return MealPlan.today()
def get_today(session: Session = Depends(generate_session)): """ Returns the recipe slug for the meal scheduled for today. If no meal is scheduled nothing is returned """ return MealPlan.today(session)
def export_meals(self): #! Problem Parseing Datetime Objects... May come back to this meal_plans = MealPlan.get_all(self.session) if meal_plans: meal_plans = [x.dict() for x in meal_plans] out_file = self.mealplans_dir.joinpath("mealplans.json") ExportDatabase._write_json_file(meal_plans, out_file)
def post_webhooks(): all_settings = SiteSettings.get_site_settings() if all_settings.webhooks.enabled: todays_meal = Recipe.get_by_slug(MealPlan.today()).dict() urls = all_settings.webhooks.webhookURLs for url in urls: requests.post(url, json.dumps(todays_meal, default=str))
def post_webhooks(): session = create_session() all_settings = db.get(session, "main") all_settings = SiteSettings(**all_settings) if all_settings.webhooks.enabled: todays_meal = Recipe.get_by_slug(MealPlan.today()).dict() urls = all_settings.webhooks.webhookURLs for url in urls: requests.post(url, json.dumps(todays_meal, default=str)) session.close()
def get_this_week(): """ Returns the meal plan data for this week """ return MealPlan.this_week()
def delete_meal_plan(plan_id): """ Removes a meal plan from the database """ MealPlan.delete(plan_id) return SnackResponse.success("Mealplan Deleted")
def get_all_meals(): """ Returns a list of all available Meal Plan """ return MealPlan.get_all()
def delete_meal_plan(plan_id, session: Session = Depends(generate_session)): """ Removes a meal plan from the database """ MealPlan.delete(session, plan_id) return SnackResponse.error("Mealplan Deleted")
def get_this_week(session: Session = Depends(generate_session)): """ Returns the meal plan data for this week """ return MealPlan.this_week(session)
def get_all_meals(session: Session = Depends(generate_session)): """ Returns a list of all available Meal Plan """ return MealPlan.get_all(session)