Implement user favorites feature for recipes
- Add UserFavorites MongoDB model with ObjectId references - Create authenticated API endpoints for favorites management - Add Heart icon and FavoriteButton components with toggle functionality - Display favorite button below recipe tags for logged-in users - Add Favoriten navigation link (visible only when authenticated) - Create favorites page with grid layout and search functionality - Store favorites by MongoDB ObjectId for data integrity 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
32
src/routes/rezepte/favorites/+page.server.ts
Normal file
32
src/routes/rezepte/favorites/+page.server.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import type { PageServerLoad } from "./$types";
|
||||
import { redirect } from '@sveltejs/kit';
|
||||
|
||||
export const load: PageServerLoad = async ({ fetch, locals }) => {
|
||||
const session = await locals.auth();
|
||||
|
||||
if (!session?.user?.nickname) {
|
||||
throw redirect(302, '/rezepte');
|
||||
}
|
||||
|
||||
try {
|
||||
const res = await fetch('/api/rezepte/favorites/recipes');
|
||||
if (!res.ok) {
|
||||
return {
|
||||
favorites: [],
|
||||
error: 'Failed to load favorites'
|
||||
};
|
||||
}
|
||||
|
||||
const favorites = await res.json();
|
||||
|
||||
return {
|
||||
favorites,
|
||||
session
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
favorites: [],
|
||||
error: 'Failed to load favorites'
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user