feat(api): add recipe detail, search, rating, favorite, cooked, comments endpoints

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-17 15:23:00 +02:00
parent 7c62c977c4
commit 45275e56a9
6 changed files with 187 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import type { RequestHandler } from './$types';
import { json, error } from '@sveltejs/kit';
import { z } from 'zod';
import { getDb } from '$lib/server/db';
import { logCooked } from '$lib/server/recipes/actions';
const Schema = z.object({ profile_id: z.number().int().positive() });
function parseId(raw: string): number {
const id = Number(raw);
if (!Number.isInteger(id) || id <= 0) error(400, { message: 'Invalid id' });
return id;
}
export const POST: RequestHandler = async ({ params, request }) => {
const id = parseId(params.id!);
const body = await request.json().catch(() => null);
const parsed = Schema.safeParse(body);
if (!parsed.success) error(400, { message: 'Invalid body' });
const entry = logCooked(getDb(), id, parsed.data.profile_id);
return json(entry, { status: 201 });
};