mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-10 04:15:38 -05:00
feat: Offline Shopping List (#3760)
Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com>
This commit is contained in:
@@ -15,10 +15,9 @@ from .._model_utils import GUID, auto_init
|
||||
from ..recipe.ingredient import IngredientFoodModel, IngredientUnitModel
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from group import Group
|
||||
from users import User
|
||||
|
||||
from ..recipe import RecipeModel
|
||||
from ..users import User
|
||||
from .group import Group
|
||||
|
||||
|
||||
class ShoppingListItemRecipeReference(BaseMixins, SqlAlchemyBase):
|
||||
@@ -73,7 +72,7 @@ class ShoppingListItem(SqlAlchemyBase, BaseMixins):
|
||||
recipe_references: Mapped[list[ShoppingListItemRecipeReference]] = orm.relationship(
|
||||
ShoppingListItemRecipeReference, cascade="all, delete, delete-orphan"
|
||||
)
|
||||
model_config = ConfigDict(exclude={"id", "label", "food", "unit"})
|
||||
model_config = ConfigDict(exclude={"label", "food", "unit"})
|
||||
|
||||
@api_extras
|
||||
@auto_init()
|
||||
|
||||
@@ -136,11 +136,7 @@ class ShoppingListItemController(BaseCrudController):
|
||||
def delete_many(self, ids: list[UUID4] = Query(None)):
|
||||
items = self.service.bulk_delete_items(ids)
|
||||
publish_list_item_events(self.publish_event, items)
|
||||
|
||||
message = (
|
||||
f"Successfully deleted {len(items.deleted_items)} {'item' if len(items.deleted_items) == 1 else 'items'}"
|
||||
)
|
||||
return SuccessResponse.respond(message=message)
|
||||
return SuccessResponse.respond()
|
||||
|
||||
@item_router.delete("/{item_id}", response_model=SuccessResponse)
|
||||
def delete_one(self, item_id: UUID4):
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from uuid import UUID
|
||||
|
||||
from pydantic import UUID4, ConfigDict, field_validator, model_validator
|
||||
from sqlalchemy.orm import joinedload, selectinload
|
||||
@@ -75,8 +76,21 @@ class ShoppingListItemBase(RecipeIngredientBase):
|
||||
|
||||
|
||||
class ShoppingListItemCreate(ShoppingListItemBase):
|
||||
id: UUID4 | None = None
|
||||
"""The unique id of the item to create. If not supplied, one will be generated."""
|
||||
recipe_references: list[ShoppingListItemRecipeRefCreate] = []
|
||||
|
||||
@field_validator("id", mode="before")
|
||||
def validate_id(cls, v):
|
||||
v = v or None
|
||||
if not v or isinstance(v, UUID):
|
||||
return v
|
||||
|
||||
try:
|
||||
return UUID(v)
|
||||
except Exception:
|
||||
return None
|
||||
|
||||
|
||||
class ShoppingListItemUpdate(ShoppingListItemBase):
|
||||
recipe_references: list[ShoppingListItemRecipeRefCreate | ShoppingListItemRecipeRefUpdate] = []
|
||||
|
||||
@@ -22,7 +22,7 @@ class SuccessResponse(BaseModel):
|
||||
error: bool = False
|
||||
|
||||
@classmethod
|
||||
def respond(cls, message: str) -> dict:
|
||||
def respond(cls, message: str = "") -> dict:
|
||||
"""
|
||||
This method is an helper to create an object and convert to a dictionary
|
||||
in the same call, for use while providing details to a HTTPException
|
||||
|
||||
Reference in New Issue
Block a user