Changes between Initial Version and Version 1 of UC0007


Ignore:
Timestamp:
09/24/26 13:50:52 (4 days ago)
Author:
231285
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • UC0007

    v1 v1  
     1= Use-case 0007 — Manage watchlist =
     2
     3'''Initiating actor:''' Trader
     4
     5'''Other actors:''' —
     6
     7A Trader keeps a list of crypto assets they want to monitor. Adding an asset that is already on the list is a no-op (idempotent).
     8
     9== Scenario ==
     10
     11 1. Trader chooses "Manage watchlist".
     12 2. System ensures the Trader has a default watchlist named "Favorites":
     13
     14{{{
     15SELECT id FROM project.watchlists
     16 WHERE user_id = $1
     17 ORDER BY created_at LIMIT 1;
     18
     19-- if no row:
     20INSERT INTO project.watchlists (user_id, name)
     21VALUES ($1, 'Favorites')
     22RETURNING id;
     23}}}
     24
     25 3. System shows the sub-menu: List / Add / Remove / Back.
     26
     27=== List items ===
     28
     29{{{
     30SELECT c.symbol, c.name, COALESCE(lp.price, 0)
     31  FROM project.watchlist_items wi
     32  JOIN project.crypto c ON c.id = wi.crypto_id
     33  LEFT JOIN project.markets m
     34         ON m.crypto_id = c.id AND m.quote_currency = 'USD'
     35  LEFT JOIN project.v_latest_prices lp
     36         ON lp.market_id = m.id
     37 WHERE wi.watchlist_id = $1
     38 ORDER BY c.symbol;
     39}}}
     40
     41=== Add a crypto ===
     42
     43{{{
     44-- 1. resolve the symbol to a crypto_id
     45SELECT id FROM project.crypto WHERE upper(symbol) = upper($1);
     46
     47-- 2. insert the item; do nothing if it's already there
     48INSERT INTO project.watchlist_items (watchlist_id, crypto_id)
     49VALUES ($watchlist_id, $crypto_id)
     50ON CONFLICT (watchlist_id, crypto_id) DO NOTHING;
     51}}}
     52
     53=== Remove a crypto ===
     54
     55{{{
     56DELETE FROM project.watchlist_items
     57 WHERE watchlist_id = $1
     58   AND crypto_id = (
     59       SELECT id FROM project.crypto
     60        WHERE upper(symbol) = upper($2)
     61   );
     62}}}
     63
     64If the delete affects zero rows, system shows "Not in watchlist."