feat(cooked): „Heute gekocht" räumt Wunschliste für das Rezept
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m18s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m18s
Wenn ein Rezept heute gekocht wurde, ist der Wunsch eingelöst — raus damit aus der Wunschliste aller Profile. Server tut das beim POST in einem Rutsch (removeFromWishlistForAll) und meldet removed_from_wishlist in der Response zurück. Der Client räumt daraufhin den lokalen wishlistProfileIds-State und refresht den Badge-Zähler, damit der Wunschliste-Button und das Header-Badge sofort passen — kein Reload nötig. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -3,6 +3,7 @@ import { json, error } from '@sveltejs/kit';
|
||||
import { z } from 'zod';
|
||||
import { getDb } from '$lib/server/db';
|
||||
import { logCooked } from '$lib/server/recipes/actions';
|
||||
import { removeFromWishlistForAll } from '$lib/server/wishlist/repository';
|
||||
|
||||
const Schema = z.object({ profile_id: z.number().int().positive() });
|
||||
|
||||
@@ -17,6 +18,11 @@ export const POST: RequestHandler = async ({ params, request }) => {
|
||||
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 });
|
||||
const db = getDb();
|
||||
const entry = logCooked(db, id, parsed.data.profile_id);
|
||||
// Wenn das Rezept heute gekocht wurde, ist der Wunsch erfüllt — für alle
|
||||
// Profile raus aus der Wunschliste. Client nutzt den removed_from_wishlist-
|
||||
// Flag, um den lokalen State (Badge, Button) ohne Reload zu aktualisieren.
|
||||
removeFromWishlistForAll(db, id);
|
||||
return json({ ...entry, removed_from_wishlist: true }, { status: 201 });
|
||||
};
|
||||
|
||||
@@ -111,6 +111,10 @@
|
||||
});
|
||||
const entry = await res.json();
|
||||
cookingLog = [entry, ...cookingLog];
|
||||
if (entry.removed_from_wishlist) {
|
||||
wishlistProfileIds = [];
|
||||
void wishlistStore.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
async function addComment() {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { insertRecipe } from '../../src/lib/server/recipes/repository';
|
||||
import {
|
||||
addToWishlist,
|
||||
removeFromWishlist,
|
||||
removeFromWishlistForAll,
|
||||
listWishlist,
|
||||
listWishlistProfileIds,
|
||||
isOnMyWishlist,
|
||||
@@ -129,4 +130,14 @@ describe('per-user wishlist', () => {
|
||||
addToWishlist(db, r2, a.id);
|
||||
expect(countWishlistRecipes(db)).toBe(2);
|
||||
});
|
||||
|
||||
it('removeFromWishlistForAll drops every profile', () => {
|
||||
const r1 = insertRecipe(db, recipe('R1'));
|
||||
const a = createProfile(db, 'A');
|
||||
const b = createProfile(db, 'B');
|
||||
addToWishlist(db, r1, a.id);
|
||||
addToWishlist(db, r1, b.id);
|
||||
removeFromWishlistForAll(db, r1);
|
||||
expect(listWishlistProfileIds(db, r1)).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user