mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-25 08:09:41 +02:00
* Changed uvicorn port to 80 * Changed port in docker-compose to match dockerfile * Readded environment variables in docker-compose * production image rework * Use opengraph metadata to make basic recipe cards when full recipe metadata is not available * fixed instrucitons on parse * add last_recipe * automated testing * roadmap update * Sqlite (#75) * file structure * auto-test * take 2 * refactor ap scheduler and startup process * fixed scraper error * database abstraction * database abstraction * port recipes over to new schema * meal migration * start settings migration * finale mongo port * backup improvements * migration imports to new DB structure * unused import cleanup * docs strings * settings and theme import logic * cleanup * fixed tinydb error * requirements * fuzzy search * remove scratch file * sqlalchemy models * improved search ui * recipe models almost done * sql modal population * del scratch * rewrite database model mixins * mostly grabage * recipe updates * working sqllite * remove old files and reorganize * final cleanup Co-authored-by: Hayden <hay-kot@pm.me> * Backup card (#78) * backup / import dialog * upgrade to new tag method * New import card * rename settings.py to app_config.py * migrate to poetry for development * fix failing test Co-authored-by: Hayden <hay-kot@pm.me> * added mkdocs to docker-compose * Translations (#72) * Translations + danish * changed back proxy target to use ENV * Resolved more merge conflicts * Removed test in translation * Documentation of translations * Updated translations * removed old packages Co-authored-by: Hayden <64056131+hay-kot@users.noreply.github.com> * fail to start bug fixes * feature: prep/cook/total time slots (#80) Co-authored-by: Hayden <hay-kot@pm.me> * missing bind attributes * Bug fixes (#81) * fix: url remains after succesful import * docs: changelog + update todos * arm image * arm compose * compose updates * update poetry * arm support Co-authored-by: Hayden <hay-kot@pm.me> * dockerfile hotfix * dockerfile hotfix * Version Release Final Touches (#84) * Remove slim * bug: opacity issues * bug: startup failure with no database * ci/cd on dev branch * formatting * v0.1.0 documentation Co-authored-by: Hayden <hay-kot@pm.me> * db init hotfix * bug: fix crash in mongo * fix mongo bug * fixed version notifier * finale changelog Co-authored-by: kentora <=> Co-authored-by: Hayden <hay-kot@pm.me> Co-authored-by: Richard Mitic <richard.h.mitic@gmail.com> Co-authored-by: kentora <kentora@kentora.dk>
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
from typing import List
|
|
|
|
from app_config import USE_MONGO, USE_SQL
|
|
|
|
from db.db_base import BaseDocument
|
|
from db.db_setup import USE_MONGO, USE_SQL
|
|
from db.mongo.meal_models import MealDocument, MealPlanDocument
|
|
from db.sql.db_session import create_session
|
|
from db.sql.meal_models import MealPlanModel
|
|
|
|
|
|
class _Meals(BaseDocument):
|
|
def __init__(self) -> None:
|
|
self.primary_key = "uid"
|
|
if USE_SQL:
|
|
self.sql_model = MealPlanModel
|
|
self.create_session = create_session
|
|
|
|
self.document = MealPlanDocument
|
|
|
|
@staticmethod
|
|
def _process_meals(meals: List[dict]) -> List[MealDocument]:
|
|
"""Turns a list of Meals in dictionary form into a list of
|
|
MealDocuments that can be attached to a MealPlanDocument
|
|
|
|
|
|
Args: \n
|
|
meals (List[dict]): From a Pydantic Class in meal_services.py \n
|
|
|
|
Returns:
|
|
a List of MealDocuments
|
|
"""
|
|
meal_docs = []
|
|
for meal in meals:
|
|
meal_doc = MealDocument(**meal)
|
|
meal_docs.append(meal_doc)
|
|
|
|
return meal_docs
|
|
|
|
def save_new_mongo(self, plan_data: dict) -> None:
|
|
"""Saves a new meal plan into the database
|
|
|
|
Args: \n
|
|
plan_data (dict): From a Pydantic Class in meal_services.py \n
|
|
"""
|
|
|
|
if USE_MONGO:
|
|
plan_data["meals"] = _Meals._process_meals(plan_data["meals"])
|
|
document = self.document(**plan_data)
|
|
|
|
document.save()
|
|
elif USE_SQL:
|
|
pass
|
|
|
|
def update_mongo(self, uid: str, plan_data: dict) -> dict:
|
|
if USE_MONGO:
|
|
document = self.document.objects.get(uid=uid)
|
|
if document:
|
|
new_meals = _Meals._process_meals(plan_data["meals"])
|
|
document.update(set__meals=new_meals)
|
|
document.save()
|
|
elif USE_SQL:
|
|
pass
|