feat: persist customer product and shop favorites through the live API
Replace mall fixture favorites with customer-scoped endpoints, and send signed-out shoppers back to the page they left after sign-in. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
94a64ec712
commit
6c1357ec4d
@@ -0,0 +1,25 @@
|
||||
-- Customer favorites: one row per (user, product) or (user, shop).
|
||||
-- Two nullable FKs plus a check keep the target shape honest; partial unique
|
||||
-- indexes enforce uniqueness without letting NULL shop/product repeat.
|
||||
|
||||
CREATE TABLE favorites (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
user_id UUID NOT NULL REFERENCES users (id) ON DELETE CASCADE,
|
||||
product_id UUID REFERENCES products (id) ON DELETE CASCADE,
|
||||
shop_id UUID REFERENCES shops (id) ON DELETE CASCADE,
|
||||
created_at TIMESTAMPTZ NOT NULL DEFAULT now(),
|
||||
CONSTRAINT favorites_exactly_one_target CHECK (
|
||||
(product_id IS NOT NULL AND shop_id IS NULL)
|
||||
OR (product_id IS NULL AND shop_id IS NOT NULL)
|
||||
)
|
||||
);
|
||||
|
||||
CREATE INDEX favorites_user_created_idx ON favorites (user_id, created_at DESC);
|
||||
|
||||
CREATE UNIQUE INDEX favorites_user_product_idx
|
||||
ON favorites (user_id, product_id)
|
||||
WHERE product_id IS NOT NULL;
|
||||
|
||||
CREATE UNIQUE INDEX favorites_user_shop_idx
|
||||
ON favorites (user_id, shop_id)
|
||||
WHERE shop_id IS NOT NULL;
|
||||
Reference in New Issue
Block a user