add hidden recipe field

This commit is contained in:
taogaetz 2025-09-11 12:43:28 -04:00
parent 3d043d9ade
commit f8c205e9d3
8 changed files with 71 additions and 4 deletions

View File

@ -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;

View File

@ -25,6 +25,7 @@ model Recipe {
photoUrl String?
time String @default("Medium") // Quick, Medium, Long
station String @default("Pans") // Garde Manger, Pans, Grill
hidden Boolean @default(false) // Hidden from non-chefs
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt

View File

@ -3,8 +3,10 @@ import type { LayoutServerLoad } from './$types';
import prisma from '$lib/server/prisma';
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({
where: locals.authenticated ? {} : { hidden: false },
include: {
ingredients: {
include: {

View File

@ -2,7 +2,7 @@ import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit';
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({
where: { id: params.id },
include: {
@ -18,5 +18,10 @@ export const load: PageServerLoad = async ({ params }) => {
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 };
};

View File

@ -465,6 +465,26 @@
</label>
</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">
<span class="label"><span class="label-text font-bold">Photo (optional)</span></span>
<input

View File

@ -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 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;
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,
photoUrl: photoUrl || existingRecipe.photoUrl, // Keep existing photo if no new one uploaded
time,
station
station,
hidden
}
});

View File

@ -420,6 +420,21 @@
</label>
</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">
<span class="label"><span class="label-text font-bold">Photo (optional)</span></span>
<input

View File

@ -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 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;
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,
photoUrl,
time,
station
station,
hidden
}
});