1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-24 15:49:42 +02:00

Refactor Shopping List API (#2021)

* tidied up shopping list item models
redefined recipe refs and updated models
added calculated display attribute to unify shopping list item rendering
added validation to use a food's label if an item's label is null

* fixed schema reference

* refactored shopping list item service
route all operations through one central method to account for edgecases
return item collections for all operations to account for merging
consolidate recipe items before sending them to the shopping list

* made fractions prettier

* replaced redundant display text util

* fixed edgecase for zero quantity items on a recipe

* fix for pre-merging recipe ingredients

* fixed edgecase for merging create_items together

* fixed bug with merged updated items creating dupes

* added test for self-removing recipe ref

* update items are now merged w/ existing items

* refactored service to make it easier to read

* added a lot of tests

* made it so checked items are never merged

* fixed bug with dragging + re-ordering

* fix for postgres cascade issue

* added prevalidator to recipe ref to avoid db error
This commit is contained in:
Michael Genson 2023-01-28 18:45:02 -06:00 committed by GitHub
parent 3415a9c310
commit 617cc1fdfb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 1398 additions and 576 deletions

View file

@ -245,6 +245,9 @@ export interface SetPermissions {
canInvite?: boolean;
canOrganize?: boolean;
}
export interface ShoppingListAddRecipeParams {
recipeIncrementQuantity?: number;
}
export interface ShoppingListCreate {
name?: string;
extras?: {
@ -253,6 +256,20 @@ export interface ShoppingListCreate {
createdAt?: string;
updateAt?: string;
}
export interface ShoppingListItemBase {
shoppingListId: string;
checked?: boolean;
position?: number;
isFood?: boolean;
note?: string;
quantity?: number;
foodId?: string;
labelId?: string;
unitId?: string;
extras?: {
[k: string]: unknown;
};
}
export interface ShoppingListItemCreate {
shoppingListId: string;
checked?: boolean;
@ -260,28 +277,38 @@ export interface ShoppingListItemCreate {
isFood?: boolean;
note?: string;
quantity?: number;
unitId?: string;
unit?: IngredientUnit;
foodId?: string;
food?: IngredientFood;
labelId?: string;
recipeReferences?: ShoppingListItemRecipeRef[];
unitId?: string;
extras?: {
[k: string]: unknown;
};
createdAt?: string;
updateAt?: string;
recipeReferences?: ShoppingListItemRecipeRefCreate[];
}
export interface IngredientUnit {
name: string;
description?: string;
export interface ShoppingListItemRecipeRefCreate {
recipeId: string;
recipeQuantity?: number;
recipeScale?: number;
}
export interface ShoppingListItemOut {
shoppingListId: string;
checked?: boolean;
position?: number;
isFood?: boolean;
note?: string;
quantity?: number;
foodId?: string;
labelId?: string;
unitId?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
id: string;
display?: string;
food?: IngredientFood;
label?: MultiPurposeLabelSummary;
unit?: IngredientUnit;
recipeReferences?: ShoppingListItemRecipeRefOut[];
createdAt?: string;
updateAt?: string;
}
@ -303,34 +330,30 @@ export interface MultiPurposeLabelSummary {
groupId: string;
id: string;
}
export interface ShoppingListItemRecipeRef {
recipeId: string;
recipeQuantity?: number;
}
export interface ShoppingListItemOut {
shoppingListId: string;
checked?: boolean;
position?: number;
isFood?: boolean;
note?: string;
quantity?: number;
unitId?: string;
unit?: IngredientUnit;
foodId?: string;
food?: IngredientFood;
labelId?: string;
recipeReferences?: (ShoppingListItemRecipeRef | ShoppingListItemRecipeRefOut)[];
export interface IngredientUnit {
name: string;
description?: string;
extras?: {
[k: string]: unknown;
};
fraction?: boolean;
abbreviation?: string;
useAbbreviation?: boolean;
id: string;
createdAt?: string;
updateAt?: string;
id: string;
label?: MultiPurposeLabelSummary;
}
export interface ShoppingListItemRecipeRefOut {
recipeId: string;
recipeQuantity?: number;
recipeScale?: number;
id: string;
shoppingListItemId: string;
}
export interface ShoppingListItemRecipeRefUpdate {
recipeId: string;
recipeQuantity?: number;
recipeScale?: number;
id: string;
shoppingListItemId: string;
}
@ -341,19 +364,41 @@ export interface ShoppingListItemUpdate {
isFood?: boolean;
note?: string;
quantity?: number;
unitId?: string;
unit?: IngredientUnit;
foodId?: string;
food?: IngredientFood;
labelId?: string;
recipeReferences?: ShoppingListItemRecipeRef[];
unitId?: string;
extras?: {
[k: string]: unknown;
};
createdAt?: string;
updateAt?: string;
recipeReferences?: (ShoppingListItemRecipeRefCreate | ShoppingListItemRecipeRefUpdate)[];
}
/**
* Only used for bulk update operations where the shopping list item id isn't already supplied
*/
export interface ShoppingListItemUpdateBulk {
shoppingListId: string;
checked?: boolean;
position?: number;
isFood?: boolean;
note?: string;
quantity?: number;
foodId?: string;
labelId?: string;
unitId?: string;
extras?: {
[k: string]: unknown;
};
recipeReferences?: (ShoppingListItemRecipeRefCreate | ShoppingListItemRecipeRefUpdate)[];
id: string;
}
/**
* Container for bulk shopping list item changes
*/
export interface ShoppingListItemsCollectionOut {
createdItems?: ShoppingListItemOut[];
updatedItems?: ShoppingListItemOut[];
deletedItems?: ShoppingListItemOut[];
}
export interface ShoppingListOut {
name?: string;
extras?: {
@ -442,6 +487,9 @@ export interface CreateIngredientFood {
};
labelId?: string;
}
export interface ShoppingListRemoveRecipeParams {
recipeDecrementQuantity?: number;
}
export interface ShoppingListSave {
name?: string;
extras?: {

View file

@ -69,6 +69,7 @@ export interface LongLiveTokenOut {
token: string;
name: string;
id: number;
createdAt?: string;
}
export interface ReadGroupPreferences {
privateGroup?: boolean;

View file

@ -4,7 +4,7 @@ import {
ShoppingListCreate,
ShoppingListItemCreate,
ShoppingListItemOut,
ShoppingListItemUpdate,
ShoppingListItemUpdateBulk,
ShoppingListOut,
ShoppingListUpdate,
} from "~/lib/api/types/group";
@ -37,7 +37,7 @@ export class ShoppingListsApi extends BaseCRUDAPI<ShoppingListCreate, ShoppingLi
export class ShoppingListItemsApi extends BaseCRUDAPI<
ShoppingListItemCreate,
ShoppingListItemOut,
ShoppingListItemUpdate
ShoppingListItemUpdateBulk
> {
baseRoute = routes.shoppingListItems;
itemRoute = routes.shoppingListItemsId;