| | 1 | == Use-case 6 - Favorite Build |
| | 2 | |
| | 3 | Initiating actor: User \\ |
| | 4 | Other actors: / \\ |
| | 5 | |
| | 6 | The registered user wants to add a build to a list of favorite builds. The system ensures the user is logged in and that the build exists. Then it stores the build as 'favorited' for that user. |
| | 7 | |
| | 8 | == Scenario |
| | 9 | |
| | 10 | Step 1. User goes to the COMPLETED BUILDS page. \\ |
| | 11 | Step 2. System gets the approved builds that the user can see. \\ |
| | 12 | {{{ |
| | 13 | SELECT |
| | 14 | b.id, |
| | 15 | b.name, |
| | 16 | b.total_price, |
| | 17 | b.created_at |
| | 18 | FROM build b |
| | 19 | WHERE b.is_approved = TRUE; |
| | 20 | }}} |
| | 21 | Step 3. The user selects a build that he wants to favorite from the page. |
| | 22 | Step 4. The user clicks on ADD TO FAVORITES button. |
| | 23 | Step 5. The system checks if the build has already been added to the favorites list: |
| | 24 | {{{ |
| | 25 | SELECT * |
| | 26 | FROM favorite_builds |
| | 27 | WHERE user_id = userId |
| | 28 | AND build_id = buildId |
| | 29 | LIMIT 1; |
| | 30 | }}} |
| | 31 | * If the build hasn't already been favorited, the system inserts it: |
| | 32 | {{{ |
| | 33 | INSERT INTO favorite_builds (user_id, build_id) |
| | 34 | VALUES (userId, buildId); |
| | 35 | }}} |
| | 36 | * If the build was already favorited, the system removes it from the favorites list: |
| | 37 | {{{ |
| | 38 | DELETE FROM favorite_builds |
| | 39 | WHERE user_id = userId |
| | 40 | AND build_id = buildId; |
| | 41 | }}} |
| | 42 | Step 6. The user can see his favorited builds in the user dashboard, by clicking on the username in the top right corner. |