Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
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")
Ejemplo n.º 3
0
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")
Ejemplo n.º 4
0
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")
Ejemplo n.º 5
0
def get_today():
    """
    Returns the recipe slug for the meal scheduled for today.
    If no meal is scheduled nothing is returned
    """

    return MealPlan.today()
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
    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)
Ejemplo n.º 8
0
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))
Ejemplo n.º 9
0
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()
Ejemplo n.º 10
0
def get_this_week():
    """ Returns the meal plan data for this week """

    return MealPlan.this_week()
Ejemplo n.º 11
0
def delete_meal_plan(plan_id):
    """ Removes a meal plan from the database """

    MealPlan.delete(plan_id)

    return SnackResponse.success("Mealplan Deleted")
Ejemplo n.º 12
0
def get_all_meals():
    """ Returns a list of all available Meal Plan """

    return MealPlan.get_all()
Ejemplo n.º 13
0
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")
Ejemplo n.º 14
0
def get_this_week(session: Session = Depends(generate_session)):
    """ Returns the meal plan data for this week """

    return MealPlan.this_week(session)
Ejemplo n.º 15
0
def get_all_meals(session: Session = Depends(generate_session)):
    """ Returns a list of all available Meal Plan """

    return MealPlan.get_all(session)