source: docs/P3-UseCaseModel/UseCase0007.md@ df05838

main
Last change on this file since df05838 was b715712, checked in by Stefan <trsunovstefan@…>, 8 weeks ago

Add the server side and configuration

  • Property mode set to 100644
File size: 1.6 KB
Line 
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
111. Trader chooses "Manage watchlist".
122. System ensures the Trader has a default watchlist named "Favorites":
13
14 ```sql
15 SELECT id FROM project.watchlists
16 WHERE user_id = $1
17 ORDER BY created_at LIMIT 1;
18
19 -- if no row:
20 INSERT INTO project.watchlists (user_id, name)
21 VALUES ($1, 'Favorites')
22 RETURNING id;
23 ```
243. System shows the sub-menu: List / Add / Remove / Back.
25
26### List items
27
28```sql
29SELECT c.symbol, c.name, COALESCE(lp.price, 0)
30 FROM project.watchlist_items wi
31 JOIN project.crypto c ON c.id = wi.crypto_id
32 LEFT JOIN project.markets m
33 ON m.crypto_id = c.id AND m.quote_currency = 'USD'
34 LEFT JOIN project.v_latest_prices lp
35 ON lp.market_id = m.id
36 WHERE wi.watchlist_id = $1
37 ORDER BY c.symbol;
38```
39
40### Add a crypto
41
42```sql
43-- 1. resolve the symbol to a crypto_id
44SELECT id FROM project.crypto WHERE upper(symbol) = upper($1);
45
46-- 2. insert the item; do nothing if it's already there
47INSERT INTO project.watchlist_items (watchlist_id, crypto_id)
48VALUES ($watchlist_id, $crypto_id)
49ON CONFLICT (watchlist_id, crypto_id) DO NOTHING;
50```
51
52### Remove a crypto
53
54```sql
55DELETE FROM project.watchlist_items
56 WHERE watchlist_id = $1
57 AND crypto_id = (
58 SELECT id FROM project.crypto
59 WHERE upper(symbol) = upper($2)
60 );
61```
62
63If the delete affects zero rows, system shows "Not in watchlist."
Note: See TracBrowser for help on using the repository browser.