Ignore:
Timestamp:
09/24/26 17:43:19 (6 days ago)
Author:
Stefan <trsunovstefan@…>
Branches:
main
Children:
0cee8ec
Parents:
a531b45
Message:

Wiki docs, phase 6 and phase 7 added

File:
1 edited

Legend:

Unmodified
Added
Removed
  • docs/P3-UseCaseModel/UseCase0007.md

    ra531b45 ref1c1c7  
    4040### Add a crypto
    4141
     42The Trader picks the crypto by its number from the listed cryptos that are not on the watchlist yet:
     43
    4244```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
     46SELECT 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;
    4551
    46 -- 2. insert the item; do nothing if it's already there
     52-- 2. insert the chosen crypto ($2 = its id from the list); do nothing if it's already there
    4753INSERT INTO project.watchlist_items (watchlist_id, crypto_id)
    48 VALUES ($watchlist_id, $crypto_id)
     54VALUES ($1, $2)
    4955ON CONFLICT (watchlist_id, crypto_id) DO NOTHING;
    5056```
    … …  
    5258### Remove a crypto
    5359
     60The Trader picks the crypto by its number from the listed cryptos on the watchlist:
     61
    5462```sql
     63-- 1. list, numbered, the cryptos on the watchlist
     64SELECT 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)
    5571DELETE 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;
    6173```
    6274
    63 If the delete affects zero rows, system shows "Not in watchlist."
     75If 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.