mirror of
				https://github.com/mealie-recipes/mealie.git
				synced 2025-11-03 18:53:17 -05:00 
			
		
		
		
	feat: ✨ (WIP) base-shoppinglist infra (#911)
* feat: ✨ base-shoppinglist infra (WIP) * add type checker * implement controllers * apply router fixes * add checked section hide/animation * add label support * formatting * fix overflow images * add experimental banner * fix #912 word break issue * remove any type errors * bump dependencies * remove templates * fix build errors * bump node version * fix template literal
This commit is contained in:
		@@ -0,0 +1,22 @@
 | 
			
		||||
import { BaseCRUDAPI } from "../_base";
 | 
			
		||||
 | 
			
		||||
const prefix = "/api";
 | 
			
		||||
 | 
			
		||||
const routes = {
 | 
			
		||||
  labels: `${prefix}/groups/labels`,
 | 
			
		||||
  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> {
 | 
			
		||||
  baseRoute = routes.labels;
 | 
			
		||||
  itemRoute = routes.labelsId;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										60
									
								
								frontend/api/class-interfaces/group-shopping-lists.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								frontend/api/class-interfaces/group-shopping-lists.ts
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,60 @@
 | 
			
		||||
import { BaseCRUDAPI } from "../_base";
 | 
			
		||||
import { ApiRequestInstance } from "~/types/api";
 | 
			
		||||
import { IngredientFood, IngredientUnit } from "~/types/api-types/recipe";
 | 
			
		||||
 | 
			
		||||
const prefix = "/api";
 | 
			
		||||
 | 
			
		||||
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}`,
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
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> {
 | 
			
		||||
  baseRoute = routes.shoppingLists;
 | 
			
		||||
  itemRoute = routes.shoppingListsId;
 | 
			
		||||
 | 
			
		||||
  async addRecipe(itemId: string, recipeId: number) {
 | 
			
		||||
    return await this.requests.post(routes.shoppingListIdAddRecipe(itemId, recipeId), {});
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class ShoppingApi {
 | 
			
		||||
  public lists: ShoppingListsApi;
 | 
			
		||||
 | 
			
		||||
  constructor(requests: ApiRequestInstance) {
 | 
			
		||||
    this.lists = new ShoppingListsApi(requests);
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user