- +server.ts: pass topN=100 so all recipes are scored in one request - RecipePicker: Empfohlen keeps top 5 with scoreDelta > 0; builds a scoreMap from all suggestions; shows green/yellow/red delta badge on every recipe in Alle Rezepte that has a score entry - Extracted scoreBadge snippet to avoid duplication between sections Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
29 lines
833 B
TypeScript
29 lines
833 B
TypeScript
import { json } from '@sveltejs/kit';
|
|
import type { RequestHandler } from './$types';
|
|
import { apiClient } from '$lib/server/api';
|
|
|
|
// GET /planner?planId=&date= — returns suggestions JSON for C4 recipe picker
|
|
export const GET: RequestHandler = async ({ fetch, url }) => {
|
|
const planId = url.searchParams.get('planId');
|
|
const date = url.searchParams.get('date');
|
|
|
|
if (!planId || !date) {
|
|
return json({ suggestions: [] });
|
|
}
|
|
|
|
try {
|
|
const api = apiClient(fetch);
|
|
const { data } = await api.GET('/v1/week-plans/{id}/suggestions', {
|
|
params: { path: { id: planId }, query: { slotDate: date, topN: 100 } }
|
|
});
|
|
|
|
const suggestions = (data?.suggestions ?? []).sort(
|
|
(a: any, b: any) => (b.scoreDelta ?? 0) - (a.scoreDelta ?? 0)
|
|
);
|
|
|
|
return json({ suggestions });
|
|
} catch {
|
|
return json({ suggestions: [] });
|
|
}
|
|
};
|