mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-08 06:55:24 +02:00
Feature/shopping lists second try (#927)
* generate types * use generated types * ui updates * init button link for common styles * add links * setup label views * add delete confirmation * reset when not saved * link label to foods and auto set when adding to shopping list * generate types * use inheritence to manage exception handling * fix schema generation and add test for open_api generation * add header to api docs * move list consilidation to service * split list and list items controller * shopping list/list item tests - PARTIAL * enable recipe add/remove in shopping lists * generate types * linting * init global utility components * update types and add list item api * fix import cycle and database error * add container and border classes * new recipe list component * fix tests * breakout item editor * refactor item editor * update bulk actions * update input / color contrast * type generation * refactor controller dependencies * include food/unit editor * remove console.logs * fix and update type generation * fix incorrect type for column * fix postgres error * fix delete by variable * auto remove refs * fix typo
This commit is contained in:
parent
f794208862
commit
92cf97e401
66 changed files with 2556 additions and 685 deletions
|
@ -1,3 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from typing import Optional
|
||||
|
||||
from fastapi_camelcase import CamelModel
|
||||
|
@ -6,6 +8,19 @@ from pydantic import UUID4
|
|||
from mealie.schema.recipe.recipe_ingredient import IngredientFood, IngredientUnit
|
||||
|
||||
|
||||
class ShoppingListItemRecipeRef(CamelModel):
|
||||
recipe_id: int
|
||||
recipe_quantity: float
|
||||
|
||||
|
||||
class ShoppingListItemRecipeRefOut(ShoppingListItemRecipeRef):
|
||||
id: UUID4
|
||||
shopping_list_item_id: UUID4
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class ShoppingListItemCreate(CamelModel):
|
||||
shopping_list_id: UUID4
|
||||
checked: bool = False
|
||||
|
@ -16,30 +31,41 @@ class ShoppingListItemCreate(CamelModel):
|
|||
note: Optional[str] = ""
|
||||
quantity: float = 1
|
||||
unit_id: int = None
|
||||
unit: IngredientUnit = None
|
||||
unit: Optional[IngredientUnit]
|
||||
food_id: int = None
|
||||
food: IngredientFood = None
|
||||
recipe_id: Optional[int] = None
|
||||
food: Optional[IngredientFood]
|
||||
|
||||
label_id: Optional[UUID4] = None
|
||||
recipe_references: list[ShoppingListItemRecipeRef] = []
|
||||
|
||||
|
||||
class ShoppingListItemOut(ShoppingListItemCreate):
|
||||
class ShoppingListItemUpdate(ShoppingListItemCreate):
|
||||
id: UUID4
|
||||
label: "Optional[MultiPurposeLabelSummary]" = None
|
||||
|
||||
|
||||
class ShoppingListItemOut(ShoppingListItemUpdate):
|
||||
label: Optional[MultiPurposeLabelSummary]
|
||||
recipe_references: list[ShoppingListItemRecipeRefOut] = []
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class ShoppingListCreate(CamelModel):
|
||||
"""
|
||||
Create Shopping List
|
||||
"""
|
||||
|
||||
name: str = None
|
||||
|
||||
|
||||
class ShoppingListRecipeRefOut(CamelModel):
|
||||
id: UUID4
|
||||
shopping_list_id: UUID4
|
||||
recipe_id: int
|
||||
recipe_quantity: float
|
||||
recipe: RecipeSummary
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
class ShoppingListSave(ShoppingListCreate):
|
||||
group_id: UUID4
|
||||
|
||||
|
@ -56,10 +82,14 @@ class ShoppingListUpdate(ShoppingListSummary):
|
|||
|
||||
|
||||
class ShoppingListOut(ShoppingListUpdate):
|
||||
recipe_references: list[ShoppingListRecipeRefOut]
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
from mealie.schema.labels import MultiPurposeLabelSummary
|
||||
from mealie.schema.labels.multi_purpose_label import MultiPurposeLabelSummary
|
||||
from mealie.schema.recipe.recipe import RecipeSummary
|
||||
|
||||
ShoppingListRecipeRefOut.update_forward_refs()
|
||||
ShoppingListItemOut.update_forward_refs()
|
||||
|
|
|
@ -1,11 +1,12 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from fastapi_camelcase import CamelModel
|
||||
from pydantic import UUID4
|
||||
|
||||
from mealie.schema.recipe import IngredientFood
|
||||
|
||||
|
||||
class MultiPurposeLabelCreate(CamelModel):
|
||||
name: str
|
||||
color: str = ""
|
||||
|
||||
|
||||
class MultiPurposeLabelSave(MultiPurposeLabelCreate):
|
||||
|
@ -24,13 +25,14 @@ class MultiPurposeLabelSummary(MultiPurposeLabelUpdate):
|
|||
|
||||
|
||||
class MultiPurposeLabelOut(MultiPurposeLabelUpdate):
|
||||
shopping_list_items: "list[ShoppingListItemOut]" = []
|
||||
foods: list[IngredientFood] = []
|
||||
# shopping_list_items: list[ShoppingListItemOut] = []
|
||||
# foods: list[IngredientFood] = []
|
||||
|
||||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
|
||||
from mealie.schema.group.group_shopping_list import ShoppingListItemOut
|
||||
# from mealie.schema.recipe.recipe_ingredient import IngredientFood
|
||||
# from mealie.schema.group.group_shopping_list import ShoppingListItemOut
|
||||
|
||||
MultiPurposeLabelOut.update_forward_refs()
|
||||
# MultiPurposeLabelOut.update_forward_refs()
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import datetime
|
||||
from pathlib import Path
|
||||
from typing import Any, Optional
|
||||
|
@ -13,7 +15,6 @@ from mealie.db.models.recipe.recipe import RecipeModel
|
|||
|
||||
from .recipe_asset import RecipeAsset
|
||||
from .recipe_comments import RecipeCommentOut
|
||||
from .recipe_ingredient import RecipeIngredient
|
||||
from .recipe_notes import RecipeNote
|
||||
from .recipe_nutrition import Nutrition
|
||||
from .recipe_settings import RecipeSettings
|
||||
|
@ -91,25 +92,25 @@ class RecipeSummary(CamelModel):
|
|||
class Config:
|
||||
orm_mode = True
|
||||
|
||||
@validator("tags", always=True, pre=True)
|
||||
@validator("tags", always=True, pre=True, allow_reuse=True)
|
||||
def validate_tags(cats: list[Any]): # type: ignore
|
||||
if isinstance(cats, list) and cats and isinstance(cats[0], str):
|
||||
return [RecipeTag(name=c, slug=slugify(c)) for c in cats]
|
||||
return cats
|
||||
|
||||
@validator("recipe_category", always=True, pre=True)
|
||||
@validator("recipe_category", always=True, pre=True, allow_reuse=True)
|
||||
def validate_categories(cats: list[Any]): # type: ignore
|
||||
if isinstance(cats, list) and cats and isinstance(cats[0], str):
|
||||
return [RecipeCategory(name=c, slug=slugify(c)) for c in cats]
|
||||
return cats
|
||||
|
||||
@validator("group_id", always=True, pre=True)
|
||||
@validator("group_id", always=True, pre=True, allow_reuse=True)
|
||||
def validate_group_id(group_id: Any):
|
||||
if isinstance(group_id, int):
|
||||
return uuid4()
|
||||
return group_id
|
||||
|
||||
@validator("user_id", always=True, pre=True)
|
||||
@validator("user_id", always=True, pre=True, allow_reuse=True)
|
||||
def validate_user_id(user_id: Any):
|
||||
if isinstance(user_id, int):
|
||||
return uuid4()
|
||||
|
@ -164,14 +165,14 @@ class Recipe(RecipeSummary):
|
|||
"extras": {x.key_name: x.value for x in name_orm.extras},
|
||||
}
|
||||
|
||||
@validator("slug", always=True, pre=True)
|
||||
@validator("slug", always=True, pre=True, allow_reuse=True)
|
||||
def validate_slug(slug: str, values):
|
||||
if not values.get("name"):
|
||||
return slug
|
||||
|
||||
return slugify(values["name"])
|
||||
|
||||
@validator("recipe_ingredient", always=True, pre=True)
|
||||
@validator("recipe_ingredient", always=True, pre=True, allow_reuse=True)
|
||||
def validate_ingredients(recipe_ingredient, values):
|
||||
if not recipe_ingredient or not isinstance(recipe_ingredient, list):
|
||||
return recipe_ingredient
|
||||
|
@ -180,3 +181,9 @@ class Recipe(RecipeSummary):
|
|||
return [RecipeIngredient(note=x) for x in recipe_ingredient]
|
||||
|
||||
return recipe_ingredient
|
||||
|
||||
|
||||
from mealie.schema.recipe.recipe_ingredient import RecipeIngredient
|
||||
|
||||
RecipeSummary.update_forward_refs()
|
||||
Recipe.update_forward_refs()
|
||||
|
|
|
@ -9,23 +9,23 @@ class ExportTypes(str, enum.Enum):
|
|||
JSON = "json"
|
||||
|
||||
|
||||
class _ExportBase(CamelModel):
|
||||
class ExportBase(CamelModel):
|
||||
recipes: list[str]
|
||||
|
||||
|
||||
class ExportRecipes(_ExportBase):
|
||||
class ExportRecipes(ExportBase):
|
||||
export_type: ExportTypes = ExportTypes.JSON
|
||||
|
||||
|
||||
class AssignCategories(_ExportBase):
|
||||
class AssignCategories(ExportBase):
|
||||
categories: list[CategoryBase]
|
||||
|
||||
|
||||
class AssignTags(_ExportBase):
|
||||
class AssignTags(ExportBase):
|
||||
tags: list[TagBase]
|
||||
|
||||
|
||||
class DeleteRecipes(_ExportBase):
|
||||
class DeleteRecipes(ExportBase):
|
||||
pass
|
||||
|
||||
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import enum
|
||||
from typing import Optional, Union
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
from fastapi_camelcase import CamelModel
|
||||
from pydantic import Field
|
||||
|
||||
uuid4()
|
||||
from pydantic import UUID4, Field
|
||||
|
||||
|
||||
class CreateIngredientFood(CamelModel):
|
||||
class UnitFoodBase(CamelModel):
|
||||
name: str
|
||||
description: str = ""
|
||||
|
||||
|
||||
class CreateIngredientUnit(CreateIngredientFood):
|
||||
fraction: bool = True
|
||||
abbreviation: str = ""
|
||||
class CreateIngredientFood(UnitFoodBase):
|
||||
label_id: UUID4 = None
|
||||
label: MultiPurposeLabelSummary = None
|
||||
|
||||
|
||||
class IngredientFood(CreateIngredientFood):
|
||||
|
@ -25,6 +25,11 @@ class IngredientFood(CreateIngredientFood):
|
|||
orm_mode = True
|
||||
|
||||
|
||||
class CreateIngredientUnit(UnitFoodBase):
|
||||
fraction: bool = True
|
||||
abbreviation: str = ""
|
||||
|
||||
|
||||
class IngredientUnit(CreateIngredientUnit):
|
||||
id: int
|
||||
|
||||
|
@ -77,3 +82,9 @@ class IngredientsRequest(CamelModel):
|
|||
class IngredientRequest(CamelModel):
|
||||
parser: RegisteredParser = RegisteredParser.nlp
|
||||
ingredient: str
|
||||
|
||||
|
||||
from mealie.schema.labels.multi_purpose_label import MultiPurposeLabelSummary
|
||||
|
||||
CreateIngredientFood.update_forward_refs()
|
||||
IngredientFood.update_forward_refs()
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
# GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
from .recipe_keys import *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue