mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-08 03:16:09 -05:00
feat: Change Recipe Owner (#4355)
Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com>
This commit is contained in:
@@ -79,19 +79,21 @@ class GroupCookbookController(BaseCrudController):
|
||||
cb = self.mixins.update_one(cookbook, cookbook.id)
|
||||
updated_by_group_and_household[cb.group_id][cb.household_id].append(cb)
|
||||
|
||||
all_updated: list[ReadCookBook] = []
|
||||
if updated_by_group_and_household:
|
||||
for group_id, household_dict in updated_by_group_and_household.items():
|
||||
for household_id, updated in household_dict.items():
|
||||
for household_id, updated_cookbooks in household_dict.items():
|
||||
all_updated.extend(updated_cookbooks)
|
||||
self.publish_event(
|
||||
event_type=EventTypes.cookbook_updated,
|
||||
document_data=EventCookbookBulkData(
|
||||
operation=EventOperation.update, cookbook_ids=[cb.id for cb in updated]
|
||||
operation=EventOperation.update, cookbook_ids=[cb.id for cb in updated_cookbooks]
|
||||
),
|
||||
group_id=group_id,
|
||||
household_id=household_id,
|
||||
)
|
||||
|
||||
return updated
|
||||
return all_updated
|
||||
|
||||
@router.get("/{item_id}", response_model=RecipeCookBook)
|
||||
def get_one(self, item_id: UUID4 | str):
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
from collections import defaultdict
|
||||
from functools import cached_property
|
||||
from shutil import copyfileobj, rmtree
|
||||
from uuid import UUID
|
||||
@@ -60,6 +61,7 @@ from mealie.schema.response.responses import ErrorResponse
|
||||
from mealie.services import urls
|
||||
from mealie.services.event_bus_service.event_types import (
|
||||
EventOperation,
|
||||
EventRecipeBulkData,
|
||||
EventRecipeBulkReportData,
|
||||
EventRecipeData,
|
||||
EventTypes,
|
||||
@@ -466,6 +468,31 @@ class RecipeController(BaseRecipeController):
|
||||
|
||||
return recipe
|
||||
|
||||
@router.put("")
|
||||
def update_many(self, data: list[Recipe]):
|
||||
updated_by_group_and_household: defaultdict[UUID4, defaultdict[UUID4, list[Recipe]]] = defaultdict(
|
||||
lambda: defaultdict(list)
|
||||
)
|
||||
for recipe in data:
|
||||
r = self.service.update_one(recipe.id, recipe) # type: ignore
|
||||
updated_by_group_and_household[r.group_id][r.household_id].append(r)
|
||||
|
||||
all_updated: list[Recipe] = []
|
||||
if updated_by_group_and_household:
|
||||
for group_id, household_dict in updated_by_group_and_household.items():
|
||||
for household_id, updated_recipes in household_dict.items():
|
||||
all_updated.extend(updated_recipes)
|
||||
self.publish_event(
|
||||
event_type=EventTypes.recipe_updated,
|
||||
document_data=EventRecipeBulkData(
|
||||
operation=EventOperation.update, recipe_slugs=[r.slug for r in updated_recipes]
|
||||
),
|
||||
group_id=group_id,
|
||||
household_id=household_id,
|
||||
)
|
||||
|
||||
return all_updated
|
||||
|
||||
@router.patch("/{slug}")
|
||||
def patch_one(self, slug: str, data: Recipe):
|
||||
"""Updates a recipe by existing slug and data."""
|
||||
|
||||
@@ -180,6 +180,8 @@ class UserOut(UserBase):
|
||||
|
||||
class UserSummary(MealieModel):
|
||||
id: UUID4
|
||||
group_id: UUID4
|
||||
household_id: UUID4
|
||||
username: str
|
||||
full_name: str
|
||||
model_config = ConfigDict(from_attributes=True)
|
||||
|
||||
@@ -138,6 +138,11 @@ class EventRecipeData(EventDocumentDataBase):
|
||||
recipe_slug: str
|
||||
|
||||
|
||||
class EventRecipeBulkData(EventDocumentDataBase):
|
||||
document_type: EventDocumentType = EventDocumentType.recipe
|
||||
recipe_slugs: list[str]
|
||||
|
||||
|
||||
class EventRecipeBulkReportData(EventDocumentDataBase):
|
||||
document_type: EventDocumentType = EventDocumentType.recipe_bulk_report
|
||||
report_id: UUID4
|
||||
|
||||
Reference in New Issue
Block a user