mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-11-29 15:14:06 -05:00
feat: Add Households to Mealie (#3970)
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user