Changeset ef1c1c7 for docs/P3-UseCaseModel/UseCase0007.md
- Timestamp:
- 09/24/26 17:43:19 (6 days ago)
- Branches:
- main
- Children:
- 0cee8ec
- Parents:
- a531b45
- File:
-
- 1 edited
-
docs/P3-UseCaseModel/UseCase0007.md (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
docs/P3-UseCaseModel/UseCase0007.md
ra531b45 ref1c1c7 40 40 ### Add a crypto 41 41 42 The Trader picks the crypto by its number from the listed cryptos that are not on the watchlist yet: 43 42 44 ```sql 43 -- 1. resolve the symbol to a crypto_id 44 SELECT id FROM project.crypto WHERE upper(symbol) = upper($1); 45 -- 1. list, numbered, the cryptos not yet on the watchlist 46 SELECT c.id, c.symbol, c.name 47 FROM project.crypto c 48 WHERE NOT EXISTS (SELECT 1 FROM project.watchlist_items wi 49 WHERE wi.watchlist_id = $1 AND wi.crypto_id = c.id) 50 ORDER BY c.symbol; 45 51 46 -- 2. insert the item; do nothing if it's already there52 -- 2. insert the chosen crypto ($2 = its id from the list); do nothing if it's already there 47 53 INSERT INTO project.watchlist_items (watchlist_id, crypto_id) 48 VALUES ($ watchlist_id, $crypto_id)54 VALUES ($1, $2) 49 55 ON CONFLICT (watchlist_id, crypto_id) DO NOTHING; 50 56 ``` … … 52 58 ### Remove a crypto 53 59 60 The Trader picks the crypto by its number from the listed cryptos on the watchlist: 61 54 62 ```sql 63 -- 1. list, numbered, the cryptos on the watchlist 64 SELECT c.id, c.symbol, c.name 65 FROM project.watchlist_items wi 66 JOIN project.crypto c ON c.id = wi.crypto_id 67 WHERE wi.watchlist_id = $1 68 ORDER BY c.symbol; 69 70 -- 2. delete the chosen crypto ($2 = its id from the list) 55 71 DELETE 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 ); 72 WHERE watchlist_id = $1 AND crypto_id = $2; 61 73 ``` 62 74 63 If the delete affects zero rows, system shows "Not in watchlist."75 If the entered number is not one of the listed numbers, system shows "Invalid choice, enter a number from 1 to N." and nothing is changed.
Note:
See TracChangeset
for help on using the changeset viewer.
