feat: Add Households to Mealie (#3970)

This commit is contained in:
Michael Genson
2024-08-22 10:14:32 -05:00
committed by GitHub
parent 0c29cef17d
commit eb170cc7e5
315 changed files with 6975 additions and 3577 deletions

View File

@@ -1,20 +1,21 @@
from datetime import datetime, timezone
from uuid import UUID
from sqlalchemy import select
from mealie.db.models.group import GroupMealPlan
from mealie.db.models.household import GroupMealPlan
from mealie.schema.meal_plan.new_meal import ReadPlanEntry
from .repository_generic import RepositoryGeneric
from .repository_generic import HouseholdRepositoryGeneric
class RepositoryMeals(RepositoryGeneric[ReadPlanEntry, GroupMealPlan]):
def by_group(self, group_id: UUID) -> "RepositoryMeals":
return super().by_group(group_id)
class RepositoryMeals(HouseholdRepositoryGeneric[ReadPlanEntry, GroupMealPlan]):
def get_today(self) -> list[ReadPlanEntry]:
if not self.household_id:
raise Exception("household_id not set")
def get_today(self, group_id: UUID) -> list[ReadPlanEntry]:
today = datetime.now(tz=timezone.utc).date()
stmt = select(GroupMealPlan).filter(GroupMealPlan.date == today, GroupMealPlan.group_id == group_id)
stmt = select(GroupMealPlan).filter(
GroupMealPlan.date == today, GroupMealPlan.household_id == self.household_id
)
plans = self.session.execute(stmt).scalars().all()
return [self.schema.model_validate(x) for x in plans]