mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-09 03:04:54 -04:00
updated models/services/tests to include user_id
This commit is contained in:
parent
74d6f58363
commit
0bf3aed287
@ -89,7 +89,7 @@ def publish_list_item_events(publisher: Callable, items_collection: ShoppingList
|
||||
class ShoppingListItemController(BaseCrudController):
|
||||
@cached_property
|
||||
def service(self):
|
||||
return ShoppingListService(self.repos, self.group)
|
||||
return ShoppingListService(self.repos, self.group, self.user)
|
||||
|
||||
@cached_property
|
||||
def repo(self):
|
||||
@ -154,7 +154,7 @@ router = APIRouter(prefix="/groups/shopping/lists", tags=["Group: Shopping Lists
|
||||
class ShoppingListController(BaseCrudController):
|
||||
@cached_property
|
||||
def service(self):
|
||||
return ShoppingListService(self.repos, self.group)
|
||||
return ShoppingListService(self.repos, self.group, self.user)
|
||||
|
||||
@cached_property
|
||||
def repo(self):
|
||||
|
@ -190,6 +190,7 @@ class ShoppingListRecipeRefOut(MealieModel):
|
||||
|
||||
class ShoppingListSave(ShoppingListCreate):
|
||||
group_id: UUID4
|
||||
user_id: UUID4
|
||||
|
||||
|
||||
class ShoppingListSummary(ShoppingListSave):
|
||||
|
@ -19,13 +19,14 @@ from mealie.schema.group.group_shopping_list import (
|
||||
)
|
||||
from mealie.schema.recipe.recipe_ingredient import IngredientFood, IngredientUnit, RecipeIngredient
|
||||
from mealie.schema.response.pagination import OrderDirection, PaginationQuery
|
||||
from mealie.schema.user.user import GroupInDB
|
||||
from mealie.schema.user.user import GroupInDB, UserOut
|
||||
|
||||
|
||||
class ShoppingListService:
|
||||
def __init__(self, repos: AllRepositories, group: GroupInDB):
|
||||
def __init__(self, repos: AllRepositories, group: GroupInDB, user: UserOut):
|
||||
self.repos = repos
|
||||
self.group = group
|
||||
self.user = user
|
||||
self.shopping_lists = repos.group_shopping_lists
|
||||
self.list_items = repos.group_shopping_list_item
|
||||
self.list_item_refs = repos.group_shopping_list_item_references
|
||||
@ -476,7 +477,7 @@ class ShoppingListService:
|
||||
return self.shopping_lists.get_one(shopping_list.id), items # type: ignore
|
||||
|
||||
def create_one_list(self, data: ShoppingListCreate):
|
||||
create_data = data.cast(ShoppingListSave, group_id=self.group.id)
|
||||
create_data = data.cast(ShoppingListSave, group_id=self.group.id, user_id=self.user.id)
|
||||
new_list = self.shopping_lists.create(create_data) # type: ignore
|
||||
|
||||
labels = self.repos.group_multi_purpose_labels.by_group(self.group.id).page_all(
|
||||
|
@ -60,7 +60,8 @@ def delete_old_checked_list_items(group_id: UUID4 | None = None):
|
||||
|
||||
for group in groups:
|
||||
event_bus_service = EventBusService(session=session, group_id=group.id)
|
||||
shopping_list_service = ShoppingListService(repos, group)
|
||||
# user is passed as None since we don't use it here
|
||||
shopping_list_service = ShoppingListService(repos, group, None) # type: ignore
|
||||
shopping_list_data = repos.group_shopping_lists.by_group(group.id).page_all(
|
||||
PaginationQuery(page=1, per_page=-1)
|
||||
)
|
||||
|
6
tests/fixtures/fixture_shopping_lists.py
vendored
6
tests/fixtures/fixture_shopping_lists.py
vendored
@ -29,7 +29,7 @@ def shopping_lists(database: AllRepositories, unique_user: TestUser):
|
||||
|
||||
for _ in range(3):
|
||||
model = database.group_shopping_lists.create(
|
||||
ShoppingListSave(name=random_string(10), group_id=unique_user.group_id),
|
||||
ShoppingListSave(name=random_string(10), group_id=unique_user.group_id, user_id=unique_user.user_id),
|
||||
)
|
||||
|
||||
models.append(model)
|
||||
@ -46,7 +46,7 @@ def shopping_lists(database: AllRepositories, unique_user: TestUser):
|
||||
@pytest.fixture(scope="function")
|
||||
def shopping_list(database: AllRepositories, unique_user: TestUser):
|
||||
model = database.group_shopping_lists.create(
|
||||
ShoppingListSave(name=random_string(10), group_id=unique_user.group_id),
|
||||
ShoppingListSave(name=random_string(10), group_id=unique_user.group_id, user_id=unique_user.user_id),
|
||||
)
|
||||
|
||||
yield model
|
||||
@ -60,7 +60,7 @@ def shopping_list(database: AllRepositories, unique_user: TestUser):
|
||||
@pytest.fixture(scope="function")
|
||||
def list_with_items(database: AllRepositories, unique_user: TestUser):
|
||||
list_model = database.group_shopping_lists.create(
|
||||
ShoppingListSave(name=random_string(10), group_id=unique_user.group_id),
|
||||
ShoppingListSave(name=random_string(10), group_id=unique_user.group_id, user_id=unique_user.user_id),
|
||||
)
|
||||
|
||||
for _ in range(10):
|
||||
|
@ -758,7 +758,7 @@ def test_pagination_order_by_nulls(
|
||||
def test_pagination_shopping_list_items_with_labels(database: AllRepositories, unique_user: TestUser):
|
||||
# create a shopping list and populate it with some items with labels, and some without labels
|
||||
shopping_list = database.group_shopping_lists.create(
|
||||
ShoppingListSave(name=random_string(), group_id=unique_user.group_id)
|
||||
ShoppingListSave(name=random_string(), group_id=unique_user.group_id, user_id=unique_user.user_id)
|
||||
)
|
||||
|
||||
labels = database.group_multi_purpose_labels.create_many(
|
||||
|
@ -14,7 +14,9 @@ def test_cleanup(database: AllRepositories, unique_user: TestUser):
|
||||
list_repo = database.group_shopping_lists.by_group(unique_user.group_id)
|
||||
list_item_repo = database.group_shopping_list_item
|
||||
|
||||
shopping_list = list_repo.create(ShoppingListSave(name=random_string(), group_id=unique_user.group_id))
|
||||
shopping_list = list_repo.create(
|
||||
ShoppingListSave(name=random_string(), group_id=unique_user.group_id, user_id=unique_user.user_id)
|
||||
)
|
||||
unchecked_items = list_item_repo.create_many(
|
||||
[
|
||||
ShoppingListItemCreate(note=random_string(), shopping_list_id=shopping_list.id)
|
||||
@ -57,7 +59,9 @@ def test_no_cleanup(database: AllRepositories, unique_user: TestUser):
|
||||
list_repo = database.group_shopping_lists.by_group(unique_user.group_id)
|
||||
list_item_repo = database.group_shopping_list_item
|
||||
|
||||
shopping_list = list_repo.create(ShoppingListSave(name=random_string(), group_id=unique_user.group_id))
|
||||
shopping_list = list_repo.create(
|
||||
ShoppingListSave(name=random_string(), group_id=unique_user.group_id, user_id=unique_user.user_id)
|
||||
)
|
||||
unchecked_items = list_item_repo.create_many(
|
||||
[
|
||||
ShoppingListItemCreate(note=random_string(), shopping_list_id=shopping_list.id)
|
||||
|
Loading…
x
Reference in New Issue
Block a user