From 1c0ce2d7416f059db4db08ab9f7109fc0a2cb315 Mon Sep 17 00:00:00 2001 From: taogaetz <59668529+taogaetz@users.noreply.github.com> Date: Wed, 3 Dec 2025 14:01:37 -0500 Subject: [PATCH] added categories for dish and ingredient --- .../migration.sql | 21 ++++++++++++ prisma/schema.prisma | 1 + src/routes/dishes/+page.server.ts | 29 ++++++++++++++++ src/routes/dishes/+page.svelte | 33 +++++++++++++++++++ src/routes/ingredients/+page.server.ts | 29 ++++++++++++++++ src/routes/ingredients/+page.svelte | 33 +++++++++++++++++++ src/routes/recipe/[id]/edit/+server.ts | 2 ++ src/routes/recipe/new/+server.ts | 2 ++ 8 files changed, 150 insertions(+) create mode 100644 prisma/migrations/20251203185248_add_recipe_type/migration.sql create mode 100644 src/routes/dishes/+page.server.ts create mode 100644 src/routes/dishes/+page.svelte create mode 100644 src/routes/ingredients/+page.server.ts create mode 100644 src/routes/ingredients/+page.svelte diff --git a/prisma/migrations/20251203185248_add_recipe_type/migration.sql b/prisma/migrations/20251203185248_add_recipe_type/migration.sql new file mode 100644 index 0000000..b43e1af --- /dev/null +++ b/prisma/migrations/20251203185248_add_recipe_type/migration.sql @@ -0,0 +1,21 @@ +-- RedefineTables +PRAGMA defer_foreign_keys=ON; +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_Recipe" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL, + "description" TEXT, + "instructions" TEXT, + "photoUrl" TEXT, + "time" TEXT NOT NULL DEFAULT 'Medium', + "station" TEXT NOT NULL DEFAULT 'Pans', + "type" TEXT NOT NULL DEFAULT 'Dish', + "hidden" BOOLEAN NOT NULL DEFAULT false, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); +INSERT INTO "new_Recipe" ("createdAt", "description", "hidden", "id", "instructions", "name", "photoUrl", "station", "time", "updatedAt") SELECT "createdAt", "description", "hidden", "id", "instructions", "name", "photoUrl", "station", "time", "updatedAt" FROM "Recipe"; +DROP TABLE "Recipe"; +ALTER TABLE "new_Recipe" RENAME TO "Recipe"; +PRAGMA foreign_keys=ON; +PRAGMA defer_foreign_keys=OFF; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 4ac6d89..cc6caa4 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -25,6 +25,7 @@ model Recipe { photoUrl String? time String @default("Medium") // Quick, Medium, Long station String @default("Pans") // Garde Manger, Pans, Grill + type String @default("Dish") // Ingredient or Dish hidden Boolean @default(false) // Hidden from non-chefs createdAt DateTime @default(now()) updatedAt DateTime @updatedAt diff --git a/src/routes/dishes/+page.server.ts b/src/routes/dishes/+page.server.ts new file mode 100644 index 0000000..cc744fc --- /dev/null +++ b/src/routes/dishes/+page.server.ts @@ -0,0 +1,29 @@ +import type { PageServerLoad } from './$types'; +import prisma from '$lib/server/prisma'; + +export const load: PageServerLoad = async ({ locals }) => { + // Get dish recipes only + // If not authenticated, filter out hidden recipes + const recipes = await prisma.recipe.findMany({ + where: { + type: 'Dish', + ...(locals.authenticated ? {} : { hidden: false }) + }, + include: { + ingredients: { + include: { + ingredient: true + } + } + }, + orderBy: { + createdAt: 'desc' + } + }); + + return { + recipes, + authenticated: locals.authenticated, + hasAccess: locals.hasAccess + }; +}; diff --git a/src/routes/dishes/+page.svelte b/src/routes/dishes/+page.svelte new file mode 100644 index 0000000..55e7bad --- /dev/null +++ b/src/routes/dishes/+page.svelte @@ -0,0 +1,33 @@ + + + + Dishes - Chef Bible + + + + + + + + Home / Dishes + + + + + {#each data.recipes as recipe} + + {/each} + + + {#if data.recipes.length === 0} + + No dish recipes found. + + {/if} + + diff --git a/src/routes/ingredients/+page.server.ts b/src/routes/ingredients/+page.server.ts new file mode 100644 index 0000000..efb69f4 --- /dev/null +++ b/src/routes/ingredients/+page.server.ts @@ -0,0 +1,29 @@ +import type { PageServerLoad } from './$types'; +import prisma from '$lib/server/prisma'; + +export const load: PageServerLoad = async ({ locals }) => { + // Get ingredient recipes only + // If not authenticated, filter out hidden recipes + const recipes = await prisma.recipe.findMany({ + where: { + type: 'Ingredient', + ...(locals.authenticated ? {} : { hidden: false }) + }, + include: { + ingredients: { + include: { + ingredient: true + } + } + }, + orderBy: { + createdAt: 'desc' + } + }); + + return { + recipes, + authenticated: locals.authenticated, + hasAccess: locals.hasAccess + }; +}; diff --git a/src/routes/ingredients/+page.svelte b/src/routes/ingredients/+page.svelte new file mode 100644 index 0000000..95885ae --- /dev/null +++ b/src/routes/ingredients/+page.svelte @@ -0,0 +1,33 @@ + + + + Ingredients - Chef Bible + + + + + + + + Home / Ingredients + + + + + {#each data.recipes as recipe} + + {/each} + + + {#if data.recipes.length === 0} + + No ingredient recipes found. + + {/if} + + diff --git a/src/routes/recipe/[id]/edit/+server.ts b/src/routes/recipe/[id]/edit/+server.ts index 62364b1..e672651 100644 --- a/src/routes/recipe/[id]/edit/+server.ts +++ b/src/routes/recipe/[id]/edit/+server.ts @@ -24,6 +24,7 @@ export const POST: RequestHandler = async ({ request, params }) => { const instructions = (formData.get('instructions') as string | null)?.trim() || null; const time = ((formData.get('time') as string | null)?.trim() || 'Medium') as string; const station = ((formData.get('station') as string | null)?.trim() || 'Pans') as string; + const type = ((formData.get('type') as string | null)?.trim() || 'Dish') as string; const hidden = formData.get('hidden') === 'on'; // Checkbox returns 'on' when checked const photo = formData.get('photo') as File | null; const parsedIngredientsRaw = formData.get('parsedIngredients') as string | null; @@ -101,6 +102,7 @@ export const POST: RequestHandler = async ({ request, params }) => { photoUrl: photoUrl || existingRecipe.photoUrl, // Keep existing photo if no new one uploaded time, station, + type, hidden } }); diff --git a/src/routes/recipe/new/+server.ts b/src/routes/recipe/new/+server.ts index 3a898a1..a0d7542 100644 --- a/src/routes/recipe/new/+server.ts +++ b/src/routes/recipe/new/+server.ts @@ -24,6 +24,7 @@ export const POST: RequestHandler = async ({ request }) => { const instructions = (formData.get('instructions') as string | null)?.trim() || null; const time = ((formData.get('time') as string | null)?.trim() || 'Medium') as string; const station = ((formData.get('station') as string | null)?.trim() || 'Pans') as string; + const type = ((formData.get('type') as string | null)?.trim() || 'Dish') as string; const hidden = formData.get('hidden') === 'on'; // Checkbox returns 'on' when checked const photo = formData.get('photo') as File | null; const parsedIngredientsRaw = formData.get('parsedIngredients') as string | null; @@ -91,6 +92,7 @@ export const POST: RequestHandler = async ({ request }) => { photoUrl, time, station, + type, hidden } });
No dish recipes found.
No ingredient recipes found.