mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-02-07 00:13:12 -05:00
* upgrade sqlalchemy to 2.0 * rewrite all db models to sqla 2.0 mapping api * fix some importing and typing weirdness * fix types of a lot of nullable columns * remove get_ref methods * fix issues found by tests * rewrite all queries in repository_recipe to 2.0 style * rewrite all repository queries to 2.0 api * rewrite all remaining queries to 2.0 api * remove now-unneeded __allow_unmapped__ flag * remove and fix some unneeded cases of "# type: ignore" * fix formatting * bump black version * run black * can this please be the last one. okay. just. okay. * fix repository errors * remove return * drop open API validator --------- Co-authored-by: Sören Busch <fleshgolem@gmx.net>
32 lines
1.1 KiB
Python
32 lines
1.1 KiB
Python
from uuid import UUID
|
|
|
|
from sqlalchemy import or_, select
|
|
|
|
from mealie.db.models.group.mealplan import GroupMealPlanRules
|
|
from mealie.schema.meal_plan.plan_rules import PlanRulesDay, PlanRulesOut, PlanRulesType
|
|
|
|
from .repository_generic import RepositoryGeneric
|
|
|
|
|
|
class RepositoryMealPlanRules(RepositoryGeneric[PlanRulesOut, GroupMealPlanRules]):
|
|
def by_group(self, group_id: UUID) -> "RepositoryMealPlanRules":
|
|
return super().by_group(group_id)
|
|
|
|
def get_rules(self, day: PlanRulesDay, entry_type: PlanRulesType) -> list[PlanRulesOut]:
|
|
stmt = select(GroupMealPlanRules).filter(
|
|
or_(
|
|
GroupMealPlanRules.day == day,
|
|
GroupMealPlanRules.day.is_(None),
|
|
GroupMealPlanRules.day == PlanRulesDay.unset.value,
|
|
),
|
|
or_(
|
|
GroupMealPlanRules.entry_type == entry_type,
|
|
GroupMealPlanRules.entry_type.is_(None),
|
|
GroupMealPlanRules.entry_type == PlanRulesType.unset.value,
|
|
),
|
|
)
|
|
|
|
rules = self.session.execute(stmt).scalars().all()
|
|
|
|
return [self.schema.from_orm(x) for x in rules]
|