Files
vmall/openspec/changes/add-favorites/specs/favorites/spec.md
T
Chengdong ZhangandCursor 6c1357ec4d 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>
2026-09-21 18:51:45 +08:00

2.2 KiB

ADDED Requirements

Requirement: Customer-owned favorite targets

A favorite SHALL belong to one authenticated customer and reference exactly one product or one shop. The database SHALL enforce target foreign keys and no more than one favorite per customer and target. Customers SHALL never read or mutate another customer's favorites.

Scenario: target shape is enforced

  • WHEN a favorite row would reference both a product and a shop or neither target
  • THEN the database rejects the row

Scenario: ownership filters every operation

  • WHEN one customer lists or removes favorites
  • THEN only that customer's rows are read or changed

Requirement: Idempotent favorite mutation

An authenticated customer SHALL add or remove a published product belonging to an active shop or an active shop as a favorite. Repeating the same add SHALL return the existing favorite without creating a duplicate, and repeating the same remove SHALL succeed with the target still unfavorited. A missing or unavailable target SHALL return 404 on add.

Scenario: repeated product add

  • WHEN a customer adds the same published product twice
  • THEN both requests succeed and exactly one favorite row exists

Scenario: repeated shop removal

  • WHEN a customer removes the same shop favorite twice
  • THEN both requests succeed and no favorite row remains

Requirement: Paginated target-aware favorite listing

An authenticated customer SHALL list favorites filtered by product or shop kind, with optional target ID and pagination. Each result SHALL be a discriminated favorite containing current public target summary data; product summaries SHALL include the current lowest active SKU price and currency. Unpublished products, products of inactive shops, and inactive shops SHALL be absent, and total SHALL count only visible results.

Scenario: buyer center loads product favorites

  • WHEN a customer lists product favorites
  • THEN each visible row contains product card data without additional per-product requests

Scenario: unavailable target is hidden

  • WHEN a favorited product becomes unpublished
  • THEN it is absent from the favorite list and total until it becomes publicly available again