Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
added aliases to food store
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-genson committed Jun 11, 2024
1 parent d14c06d commit 62454c0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
11 changes: 11 additions & 0 deletions AppLambda/src/models/mealie.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,23 @@ def __str__(self) -> str:
return self.name


class UnitFoodAlias(MealieBase):
name: str


class UnitFoodBase(MealieBase):
name: str
plural_name: str | None = None
description: str = ""
extras: dict | None = {}

aliases: list[UnitFoodAlias] | None = None
"""
List of aliases for this unit/food
Only available in v1.0.0-RC2 and later
"""


class Unit(UnitFoodBase):
id: str | None
Expand Down
9 changes: 8 additions & 1 deletion AppLambda/src/services/mealie.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,14 @@ def recipe_store(self) -> dict[str, MealieRecipe]:
def food_store(self) -> dict[str, Food]:
"""Dictionary of { food.name.lower(): Food }"""

return {food.name.lower(): food for food in self._client.get_all_foods()}
store: dict[str, Food] = {}
all_foods = self._client.get_all_foods()
for food in all_foods:
store[food.name.lower()] = food
for alias in food.aliases or []:
store[alias.name.lower()] = food

return store

@cached_property
def label_store(self) -> dict[str, Label]:
Expand Down

0 comments on commit 62454c0

Please sign in to comment.