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")
async def delete_theme(theme_name: str): """ Returns basic site Settings """ try: SiteTheme.delete_theme(theme_name) except: raise HTTPException( status_code=400, detail=SnackResponse.error("Unable to Delete Theme")) return SnackResponse.success("Theme Deleted")
async def create_theme(data: SiteTheme): """ Creates a site color theme database entry """ try: data.save_to_db() except: raise HTTPException(status_code=400, detail=SnackResponse.error("Unable to Save Theme")) return SnackResponse.success("Theme Saved")
async def update_theme(theme_name: str, data: SiteTheme): """ Update a theme database entry """ try: data.update_document() except: raise HTTPException( status_code=400, detail=SnackResponse.error("Unable to Update Theme")) return SnackResponse.success("Theme Updated")
async def delete_theme(theme_name: str): """ Deletes theme from the database """ try: SiteTheme.delete_theme(theme_name) except: raise HTTPException( status_code=400, detail=SnackResponse.error("Unable to Delete Theme")) return SnackResponse.success("Theme Deleted")
def export_database(data: BackupJob): """Generates a backup of the recipe database in json format.""" export_path = backup_all(data.tag, data.template) try: return SnackResponse.success("Backup Created at " + export_path) except: HTTPException( status_code=400, detail=SnackResponse.error("Error Creating Backup. See Log File"), )
def delete_recipe(recipe_slug: str): """ Deletes a recipe by slug """ try: Recipe.delete(recipe_slug) except: raise HTTPException( status_code=404, detail=SnackResponse.error("Unable to Delete Recipe") ) return SnackResponse.success("Recipe Deleted")
def upload_backup_zipfile(archive: UploadFile = File(...)): """ Upload a .zip File to later be imported into Mealie """ dest = BACKUP_DIR.joinpath(archive.filename) with dest.open("wb") as buffer: shutil.copyfileobj(archive.file, buffer) if dest.is_file: return SnackResponse.success("Backup uploaded") else: return SnackResponse.error("Failure uploading file")
def upload_nextcloud_zipfile(archive: UploadFile = File(...)): """ Upload a .zip File to later be imported into Mealie """ dest = MIGRATION_DIR.joinpath(archive.filename) with dest.open("wb") as buffer: shutil.copyfileobj(archive.file, buffer) if dest.is_file: return SnackResponse.success("Migration data uploaded") else: return SnackResponse.error("Failure uploading file")
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 export_database(data: BackupJob): try: export_path = export_db(data.tag, data.template) except: HTTPException( status_code=400, detail=SnackResponse.error("Error Creating Backup. See Log File"), ) return SnackResponse.success("Backup Created at " + export_path)
async def delete_backup(backup_name: str): try: BACKUP_DIR.joinpath(backup_name).unlink() except: HTTPException( status_code=400, detail=SnackResponse.error( "Unable to Delete Backup. See Log File"), ) return SnackResponse.success(f"{backup_name} Deleted")
async def export_database(data: BackupJob): """ Returns this weeks meal plan """ try: export_db(data.tag, data.template) except: HTTPException( status_code=400, detail=SnackResponse.error("Error Creating Backup. See Log File"), ) return SnackResponse.success("Backup Created in /data/backups")
async def update_settings(data: SiteSettings): """ Returns Site Settings """ try: data.update() except: raise HTTPException( status_code=400, detail=SnackResponse.error("Unable to Save Settings")) scheduler.reschedule_webhooks() return SnackResponse.success("Settings Updated")
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 delete_backup(backup_name: str): """ Removes a database backup from the file system """ try: BACKUP_DIR.joinpath(backup_name).unlink() except: HTTPException( status_code=400, detail=SnackResponse.error( "Unable to Delete Backup. See Log File"), ) return SnackResponse.success(f"{backup_name} Deleted")
def import_chowdown_recipes(repo: ChowdownURL): """ Import Chowsdown Recipes from Repo URL """ try: report = chowdow_migrate(repo.url) return SnackResponse.success( "Recipes Imported from Git Repo, see report for failures.", additional_data=report, ) except: return HTTPException( status_code=400, detail=SnackResponse.error( "Unable to Migrate Recipes. See Log for Details"), )
def export_database(data: BackupJob, session: Session = Depends(generate_session)): """Generates a backup of the recipe database in json format.""" export_path = backup_all( session=session, tag=data.tag, templates=data.templates, export_recipes=data.options.recipes, export_settings=data.options.settings, export_themes=data.options.themes, ) try: return SnackResponse.success("Backup Created at " + export_path) except: HTTPException( status_code=400, detail=SnackResponse.error("Error Creating Backup. See Log File"), )
def update_settings(data: SiteSettings, session: Session = Depends(generate_session)): """ Returns Site Settings """ db.settings.update(session, "main", data.dict()) return SnackResponse.success("Settings Updated")
def create_theme(data: SiteTheme, session: Session = Depends(generate_session)): """ Creates a site color theme database entry """ db.themes.create(session, data.dict()) return SnackResponse.success("Theme Saved")
def delete_meal_plan(plan_id): """ Removes a meal plan from the database """ MealPlan.delete(plan_id) return SnackResponse.success("Mealplan Deleted")