feat(home): „Alle Rezepte"-Sektion mit Sortierung und Endless-Scroll
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m21s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m21s
Neue Sektion unter „Zuletzt hinzugefügt": sortierbar nach Name, Bewertung, zuletzt gekocht und Hinzugefügt. Auswahl persistiert in localStorage (kochwas.allSort). - Neuer Endpoint GET /api/recipes/all?sort=name&limit=10&offset=0. - listAllRecipesPaginated(db, sort, limit, offset) im repository: NULLS-last-Emulation per CASE für rating/cooked — funktioniert auch auf älteren SQLite-Versionen. - Endless Scroll per IntersectionObserver auf ein Sentinel-Element am Listen-Ende (rootMargin 200px, damit schon vor dem harten Rand nachgeladen wird). Pagesize 10. - 4 neue Tests: Name-Sort, Rating-Sort, Cooked-Sort, Pagination-Offset. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
18
src/routes/api/recipes/all/+server.ts
Normal file
18
src/routes/api/recipes/all/+server.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
import type { RequestHandler } from './$types';
|
||||
import { json, error } from '@sveltejs/kit';
|
||||
import { getDb } from '$lib/server/db';
|
||||
import {
|
||||
listAllRecipesPaginated,
|
||||
type AllRecipesSort
|
||||
} from '$lib/server/recipes/search-local';
|
||||
|
||||
const VALID_SORTS = new Set<AllRecipesSort>(['name', 'rating', 'cooked', 'created']);
|
||||
|
||||
export const GET: RequestHandler = async ({ url }) => {
|
||||
const sortRaw = (url.searchParams.get('sort') ?? 'name') as AllRecipesSort;
|
||||
if (!VALID_SORTS.has(sortRaw)) error(400, { message: 'Invalid sort' });
|
||||
const limit = Math.min(50, Math.max(1, Number(url.searchParams.get('limit') ?? 10)));
|
||||
const offset = Math.max(0, Number(url.searchParams.get('offset') ?? 0));
|
||||
const hits = listAllRecipesPaginated(getDb(), sortRaw, limit, offset);
|
||||
return json({ sort: sortRaw, limit, offset, hits });
|
||||
};
|
||||
Reference in New Issue
Block a user