mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-07-25 08:09:41 +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,4 +1,5 @@
|
|||
import { BaseCRUDAPI } from "../_base";
|
||||
import { MultiPurposeLabelCreate, MultiPurposeLabelOut } from "~/types/api-types/labels";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
|
@ -7,16 +8,7 @@ const routes = {
|
|||
labelsId: (id: string | number) => `${prefix}/groups/labels/${id}`,
|
||||
};
|
||||
|
||||
export interface CreateLabel {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface Label extends CreateLabel {
|
||||
id: string;
|
||||
groupId: string;
|
||||
}
|
||||
|
||||
export class MultiPurposeLabelsApi extends BaseCRUDAPI<Label, CreateLabel> {
|
||||
export class MultiPurposeLabelsApi extends BaseCRUDAPI<MultiPurposeLabelOut, MultiPurposeLabelCreate> {
|
||||
baseRoute = routes.labels;
|
||||
itemRoute = routes.labelsId;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
import { BaseCRUDAPI } from "../_base";
|
||||
import { ApiRequestInstance } from "~/types/api";
|
||||
import { IngredientFood, IngredientUnit } from "~/types/api-types/recipe";
|
||||
import {
|
||||
ShoppingListCreate,
|
||||
ShoppingListItemCreate,
|
||||
ShoppingListItemOut,
|
||||
ShoppingListOut,
|
||||
} from "~/types/api-types/group";
|
||||
|
||||
const prefix = "/api";
|
||||
|
||||
|
@ -8,53 +13,49 @@ const routes = {
|
|||
shoppingLists: `${prefix}/groups/shopping/lists`,
|
||||
shoppingListsId: (id: string) => `${prefix}/groups/shopping/lists/${id}`,
|
||||
shoppingListIdAddRecipe: (id: string, recipeId: number) => `${prefix}/groups/shopping/lists/${id}/recipe/${recipeId}`,
|
||||
|
||||
shoppingListItems: `${prefix}/groups/shopping/items`,
|
||||
shoppingListItemsId: (id: string) => `${prefix}/groups/shopping/items/${id}`,
|
||||
};
|
||||
|
||||
export interface ShoppingListItemCreate {
|
||||
id: string;
|
||||
shoppingListId: string;
|
||||
checked: boolean;
|
||||
position: number;
|
||||
note: string;
|
||||
quantity: number;
|
||||
|
||||
isFood: boolean;
|
||||
unit: IngredientUnit | null;
|
||||
food: IngredientFood | null;
|
||||
|
||||
labelId: string | null;
|
||||
label?: {
|
||||
id: string;
|
||||
name: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface ShoppingListCreate {
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface ShoppingListSummary extends ShoppingListCreate {
|
||||
id: string;
|
||||
groupId: string;
|
||||
}
|
||||
|
||||
export interface ShoppingList extends ShoppingListSummary {
|
||||
listItems: ShoppingListItemCreate[];
|
||||
}
|
||||
|
||||
export class ShoppingListsApi extends BaseCRUDAPI<ShoppingList, ShoppingListCreate> {
|
||||
export class ShoppingListsApi extends BaseCRUDAPI<ShoppingListOut, ShoppingListCreate> {
|
||||
baseRoute = routes.shoppingLists;
|
||||
itemRoute = routes.shoppingListsId;
|
||||
|
||||
async addRecipe(itemId: string, recipeId: number) {
|
||||
return await this.requests.post(routes.shoppingListIdAddRecipe(itemId, recipeId), {});
|
||||
}
|
||||
|
||||
async removeRecipe(itemId: string, recipeId: number) {
|
||||
return await this.requests.delete(routes.shoppingListIdAddRecipe(itemId, recipeId));
|
||||
}
|
||||
}
|
||||
|
||||
export class ShoppingListItemsApi extends BaseCRUDAPI<ShoppingListItemOut, ShoppingListItemCreate> {
|
||||
baseRoute = routes.shoppingListItems;
|
||||
itemRoute = routes.shoppingListItemsId;
|
||||
|
||||
async updateMany(items: ShoppingListItemOut[]) {
|
||||
return await this.requests.put(routes.shoppingListItems, items);
|
||||
}
|
||||
|
||||
async deleteMany(items: ShoppingListItemOut[]) {
|
||||
let query = "?";
|
||||
|
||||
items.forEach((item) => {
|
||||
query += `ids=${item.id}&`;
|
||||
});
|
||||
|
||||
return await this.requests.delete(routes.shoppingListItems + query);
|
||||
}
|
||||
}
|
||||
|
||||
export class ShoppingApi {
|
||||
public lists: ShoppingListsApi;
|
||||
public items: ShoppingListItemsApi;
|
||||
|
||||
constructor(requests: ApiRequestInstance) {
|
||||
this.lists = new ShoppingListsApi(requests);
|
||||
this.items = new ShoppingListItemsApi(requests);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue