mirror of
https://github.com/taogaetz/chefbible.git
synced 2025-12-06 11:47:24 -05:00
add hidden recipe field
This commit is contained in:
parent
3d043d9ade
commit
f8c205e9d3
@ -0,0 +1,20 @@
|
|||||||
|
-- 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',
|
||||||
|
"hidden" BOOLEAN NOT NULL DEFAULT false,
|
||||||
|
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
"updatedAt" DATETIME NOT NULL
|
||||||
|
);
|
||||||
|
INSERT INTO "new_Recipe" ("createdAt", "description", "id", "instructions", "name", "photoUrl", "station", "time", "updatedAt") SELECT "createdAt", "description", "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;
|
||||||
@ -25,6 +25,7 @@ model Recipe {
|
|||||||
photoUrl String?
|
photoUrl String?
|
||||||
time String @default("Medium") // Quick, Medium, Long
|
time String @default("Medium") // Quick, Medium, Long
|
||||||
station String @default("Pans") // Garde Manger, Pans, Grill
|
station String @default("Pans") // Garde Manger, Pans, Grill
|
||||||
|
hidden Boolean @default(false) // Hidden from non-chefs
|
||||||
createdAt DateTime @default(now())
|
createdAt DateTime @default(now())
|
||||||
updatedAt DateTime @updatedAt
|
updatedAt DateTime @updatedAt
|
||||||
|
|
||||||
|
|||||||
@ -3,8 +3,10 @@ import type { LayoutServerLoad } from './$types';
|
|||||||
import prisma from '$lib/server/prisma';
|
import prisma from '$lib/server/prisma';
|
||||||
|
|
||||||
export const load: LayoutServerLoad = async ({ locals }) => {
|
export const load: LayoutServerLoad = async ({ locals }) => {
|
||||||
// Get all recipes for search functionality
|
// Get recipes for search functionality
|
||||||
|
// If not authenticated, filter out hidden recipes
|
||||||
const recipes = await prisma.recipe.findMany({
|
const recipes = await prisma.recipe.findMany({
|
||||||
|
where: locals.authenticated ? {} : { hidden: false },
|
||||||
include: {
|
include: {
|
||||||
ingredients: {
|
ingredients: {
|
||||||
include: {
|
include: {
|
||||||
|
|||||||
@ -2,7 +2,7 @@ import type { PageServerLoad } from './$types';
|
|||||||
import { error } from '@sveltejs/kit';
|
import { error } from '@sveltejs/kit';
|
||||||
import prisma from '$lib/server/prisma';
|
import prisma from '$lib/server/prisma';
|
||||||
|
|
||||||
export const load: PageServerLoad = async ({ params }) => {
|
export const load: PageServerLoad = async ({ params, locals }) => {
|
||||||
const recipe = await prisma.recipe.findUnique({
|
const recipe = await prisma.recipe.findUnique({
|
||||||
where: { id: params.id },
|
where: { id: params.id },
|
||||||
include: {
|
include: {
|
||||||
@ -18,5 +18,10 @@ export const load: PageServerLoad = async ({ params }) => {
|
|||||||
throw error(404, 'Recipe not found');
|
throw error(404, 'Recipe not found');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Check if recipe is hidden and user is not authenticated
|
||||||
|
if (recipe.hidden && !locals.authenticated) {
|
||||||
|
throw error(404, 'Recipe not found');
|
||||||
|
}
|
||||||
|
|
||||||
return { recipe };
|
return { recipe };
|
||||||
};
|
};
|
||||||
|
|||||||
@ -465,6 +465,26 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label class="form-control">
|
||||||
|
<div class="label">
|
||||||
|
<span class="label-text font-bold">Visibility</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<input
|
||||||
|
type="checkbox"
|
||||||
|
name="hidden"
|
||||||
|
class="checkbox checkbox-primary"
|
||||||
|
checked={data.recipe?.hidden || false}
|
||||||
|
/>
|
||||||
|
<span class="label-text">Hide from non-chefs (chef-only recipe)</span>
|
||||||
|
</div>
|
||||||
|
<div class="label">
|
||||||
|
<span class="label-text-alt text-sm text-base-content/60">
|
||||||
|
Hidden recipes will only be visible to authenticated chefs
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
|
||||||
<label class="form-control">
|
<label class="form-control">
|
||||||
<span class="label"><span class="label-text font-bold">Photo (optional)</span></span>
|
<span class="label"><span class="label-text font-bold">Photo (optional)</span></span>
|
||||||
<input
|
<input
|
||||||
|
|||||||
@ -24,6 +24,7 @@ export const POST: RequestHandler = async ({ request, params }) => {
|
|||||||
const instructions = (formData.get('instructions') as string | null)?.trim() || null;
|
const instructions = (formData.get('instructions') as string | null)?.trim() || null;
|
||||||
const time = ((formData.get('time') as string | null)?.trim() || 'Medium') as string;
|
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 station = ((formData.get('station') as string | null)?.trim() || 'Pans') as string;
|
||||||
|
const hidden = formData.get('hidden') === 'on'; // Checkbox returns 'on' when checked
|
||||||
const photo = formData.get('photo') as File | null;
|
const photo = formData.get('photo') as File | null;
|
||||||
const parsedIngredientsRaw = formData.get('parsedIngredients') as string | null;
|
const parsedIngredientsRaw = formData.get('parsedIngredients') as string | null;
|
||||||
let parsedIngredients: Array<{ name: string; quantity: number | null; unit: string | null; prep: string | null }> = [];
|
let parsedIngredients: Array<{ name: string; quantity: number | null; unit: string | null; prep: string | null }> = [];
|
||||||
@ -99,7 +100,8 @@ export const POST: RequestHandler = async ({ request, params }) => {
|
|||||||
instructions,
|
instructions,
|
||||||
photoUrl: photoUrl || existingRecipe.photoUrl, // Keep existing photo if no new one uploaded
|
photoUrl: photoUrl || existingRecipe.photoUrl, // Keep existing photo if no new one uploaded
|
||||||
time,
|
time,
|
||||||
station
|
station,
|
||||||
|
hidden
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -420,6 +420,21 @@
|
|||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<label class="form-control">
|
||||||
|
<div class="label">
|
||||||
|
<span class="label-text font-bold">Visibility</span>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-center gap-3">
|
||||||
|
<input type="checkbox" name="hidden" class="checkbox checkbox-primary" />
|
||||||
|
<span class="label-text">Hide from non-chefs (chef-only recipe)</span>
|
||||||
|
</div>
|
||||||
|
<div class="label">
|
||||||
|
<span class="label-text-alt text-sm text-base-content/60">
|
||||||
|
Hidden recipes will only be visible to authenticated chefs
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</label>
|
||||||
|
|
||||||
<label class="form-control">
|
<label class="form-control">
|
||||||
<span class="label"><span class="label-text font-bold">Photo (optional)</span></span>
|
<span class="label"><span class="label-text font-bold">Photo (optional)</span></span>
|
||||||
<input
|
<input
|
||||||
|
|||||||
@ -24,6 +24,7 @@ export const POST: RequestHandler = async ({ request }) => {
|
|||||||
const instructions = (formData.get('instructions') as string | null)?.trim() || null;
|
const instructions = (formData.get('instructions') as string | null)?.trim() || null;
|
||||||
const time = ((formData.get('time') as string | null)?.trim() || 'Medium') as string;
|
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 station = ((formData.get('station') as string | null)?.trim() || 'Pans') as string;
|
||||||
|
const hidden = formData.get('hidden') === 'on'; // Checkbox returns 'on' when checked
|
||||||
const photo = formData.get('photo') as File | null;
|
const photo = formData.get('photo') as File | null;
|
||||||
const parsedIngredientsRaw = formData.get('parsedIngredients') as string | null;
|
const parsedIngredientsRaw = formData.get('parsedIngredients') as string | null;
|
||||||
let parsedIngredients: Array<{ name: string; quantity: number | null; unit: string | null; prep: string | null }> = [];
|
let parsedIngredients: Array<{ name: string; quantity: number | null; unit: string | null; prep: string | null }> = [];
|
||||||
@ -89,7 +90,8 @@ export const POST: RequestHandler = async ({ request }) => {
|
|||||||
instructions,
|
instructions,
|
||||||
photoUrl,
|
photoUrl,
|
||||||
time,
|
time,
|
||||||
station
|
station,
|
||||||
|
hidden
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user