feat(wishlist): per-user Wünsche + Header-Badge mit Gesamtzahl
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m16s
All checks were successful
Build & Publish Docker Image / build-and-push (push) Successful in 1m16s
Schema-Änderung (Migration 005):
- Tabelle wishlist umgestellt auf PK (recipe_id, profile_id)
- wishlist_like-Tabelle zusammengelegt — Liken WAR schon "will ich auch",
also werden alle bestehenden Likes Memberships auf der neuen Tabelle.
- Alt-Einträge mit added_by_profile_id werden migriert, anonyme gehen
verloren (war inkonsistent, jetzt erzwingen wir profile_id NOT NULL).
Repository:
- listWishlist aggregiert pro Rezept: wanted_by_count, wanted_by_names
(kommagetrennt), on_my_wishlist für das aktive Profil
- listWishlistProfileIds(recipeId) für den Recipe-Page-Loader
- countWishlistRecipes für das Header-Badge (DISTINCT recipe_id)
- addToWishlist/removeFromWishlist/isOnMyWishlist alle mit profile_id
als Pflicht
API:
- POST /api/wishlist: profile_id jetzt Pflicht (nullable raus)
- DELETE /api/wishlist/[recipe_id]?profile_id=X (nur eigenes Entry)
- /api/wishlist/[recipe_id]/like komplett entfernt (Konzept obsolet)
- Neu: GET /api/wishlist/count → { count: <distinct recipes> }
UI:
- Header-Heart bekommt rotes Badge mit Zahl der Wunschliste-Rezepte.
wishlistStore in $lib/client/wishlist.svelte.ts hält den Count reaktiv;
Refresh auf Mount, nach Add/Remove, beim Öffnen der Wunschliste.
- Recipe-Detail: Loader liefert wishlist_profile_ids; onMyWishlist ist
ein $derived. Toggle fragt aktives Profil (alertAction sonst), mutiert
die lokale Liste + ruft wishlistStore.refresh.
- Wunschliste-Seite: Heart toggelt eigenen Wunsch, Count zeigt Gesamt-
wünsche, kommagetrennte Namen zeigen "wer will". Trash-Button
entfernt — Heart-off reicht jetzt.
Tests (99 → 99, 8 neu geschrieben):
- Per-User-Add/Remove, aggregierte Counts, on_my_wishlist, Cascades bei
Recipe/Profile-Delete, countWishlistRecipes = DISTINCT.
This commit is contained in:
29
src/lib/server/db/migrations/005_wishlist_per_user.sql
Normal file
29
src/lib/server/db/migrations/005_wishlist_per_user.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
-- Wishlist: from "one entry per recipe" to "per-user membership".
|
||||
-- Multiple profiles can now wish for the same recipe. The old wishlist_like
|
||||
-- table merges into this — liking WAS already "me too", so existing likes
|
||||
-- become wishlist memberships.
|
||||
|
||||
CREATE TABLE wishlist_new (
|
||||
recipe_id INTEGER NOT NULL REFERENCES recipe(id) ON DELETE CASCADE,
|
||||
profile_id INTEGER NOT NULL REFERENCES profile(id) ON DELETE CASCADE,
|
||||
added_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
PRIMARY KEY (recipe_id, profile_id)
|
||||
);
|
||||
|
||||
-- Preserve existing explicit additions (only if a profile was attached)
|
||||
INSERT OR IGNORE INTO wishlist_new (recipe_id, profile_id, added_at)
|
||||
SELECT recipe_id, added_by_profile_id, added_at
|
||||
FROM wishlist
|
||||
WHERE added_by_profile_id IS NOT NULL;
|
||||
|
||||
-- Likes become memberships
|
||||
INSERT OR IGNORE INTO wishlist_new (recipe_id, profile_id, added_at)
|
||||
SELECT recipe_id, profile_id, created_at
|
||||
FROM wishlist_like;
|
||||
|
||||
DROP TABLE wishlist_like;
|
||||
DROP TABLE wishlist;
|
||||
ALTER TABLE wishlist_new RENAME TO wishlist;
|
||||
|
||||
CREATE INDEX idx_wishlist_profile ON wishlist(profile_id);
|
||||
CREATE INDEX idx_wishlist_recipe ON wishlist(recipe_id);
|
||||
Reference in New Issue
Block a user