feat: Offline Shopping List (#3760)

Co-authored-by: boc-the-git <3479092+boc-the-git@users.noreply.github.com>
This commit is contained in:
Michael Genson
2024-06-29 04:58:58 -05:00
committed by GitHub
parent 63a180ef2c
commit f4827abc1d
14 changed files with 347 additions and 82 deletions

View File

@@ -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] = []

View File

@@ -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