Skip to content

Commit

Permalink
Add a category filter to Recipe
Browse files Browse the repository at this point in the history
  • Loading branch information
alex9smith committed Nov 5, 2024
1 parent 8ca5aff commit 31b685b
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 1 deletion.
9 changes: 9 additions & 0 deletions backend/models/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,12 @@ class Length(Enum):
UNDER_30 = "under_30"
UNDER_60 = "under_60"
OVER_60 = "over_60"


class Category(Enum):
VEGAN = "vegan"
VEGETARIAN = "vegetarian"
FISH = "fish"
MEAT = "meat"
SIDE = "side"
DESSERT = "dessert"
6 changes: 5 additions & 1 deletion backend/models/recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Enum
from uuid import uuid4
from backend.services.dynamodb import DynamoDBClient
from backend.models.filters import Difficulty, Length
from backend.models.filters import Category, Difficulty, Length

from typing import Any, Dict, List, Optional

Expand Down Expand Up @@ -46,6 +46,7 @@ def __init__(
tags: List[str],
difficulty: Difficulty,
length: Length,
category: Category,
id: Optional[str] = None,
) -> None:
self.id = id
Expand All @@ -55,6 +56,7 @@ def __init__(
self.source = source
self.difficulty = difficulty
self.length = length
self.category = category

if self.id is None:
self.id = uuid4()
Expand All @@ -74,6 +76,7 @@ def to_dict(self) -> Dict[str, str | Dict[str, str] | List[str]]:
"tags": self.tags,
"difficulty": self.difficulty.value,
"length": self.length.value,
"category": self.category.value,
}

@classmethod
Expand Down Expand Up @@ -106,6 +109,7 @@ def from_dict(cls, input: Dict[str, Any]) -> "Recipe":
ingredients=input["ingredients"],
difficulty=Difficulty(input["difficulty"]),
length=Length(input["length"]),
category=Category(input["category"]),
id=id,
)
except:
Expand Down
1 change: 1 addition & 0 deletions backend/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@
"source": SOURCE_WEBSITE_DICT,
"difficulty": "easy",
"length": "under_30",
"category": "vegetarian",
}
2 changes: 2 additions & 0 deletions backend/tests/models/test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def test_recipe_saves_id(self, dynamodb_mock: Mock):
tags=[],
difficulty="easy",
length="under_30",
category="vegetarian",
)
assert recipe.id == "id"

Expand All @@ -48,6 +49,7 @@ def test_recipe_generates_id_if_none(self, uuid_mock: Mock, dynamodb_mock: Mock)
tags=[],
difficulty="easy",
length="under_30",
category="vegetarian",
)
assert recipe.id == "generated_id"

Expand Down
1 change: 1 addition & 0 deletions scripts/post_test_recipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"source": {"type": "website", "address": "address"},
"difficulty": "easy",
"length": "under_30",
"category": "vegetarian",
},
)

Expand Down

0 comments on commit 31b685b

Please sign in to comment.