| | 1 | == User opens dashboard == |
| | 2 | |
| | 3 | === Actors === |
| | 4 | User |
| | 5 | |
| | 6 | === Scenario === |
| | 7 | 1. The user clicks on the button with their username |
| | 8 | 2. A dashboard with their information, favorited builds and their own builds is displayed. |
| | 9 | {{{ |
| | 10 | SELECT |
| | 11 | username, |
| | 12 | email |
| | 13 | FROM users |
| | 14 | WHERE id = $userId |
| | 15 | LIMIT 1; |
| | 16 | }}} |
| | 17 | {{{ |
| | 18 | SELECT |
| | 19 | id, |
| | 20 | user_id, |
| | 21 | name, |
| | 22 | created_at, |
| | 23 | total_price |
| | 24 | FROM build |
| | 25 | WHERE user_id = $userId |
| | 26 | ORDER BY created_at DESC; |
| | 27 | }}} |
| | 28 | {{{ |
| | 29 | SELECT |
| | 30 | b.id, |
| | 31 | b.user_id, |
| | 32 | b.name, |
| | 33 | b.created_at, |
| | 34 | b.total_price, |
| | 35 | COALESCE(AVG(rb.value::float), 0) AS avgRating |
| | 36 | FROM build AS b |
| | 37 | INNER JOIN favorite_build AS fb |
| | 38 | ON b.id = fb.build_id |
| | 39 | LEFT JOIN rating_build AS rb |
| | 40 | ON b.id = rb.build_id |
| | 41 | WHERE fb.user_id = $userId |
| | 42 | GROUP BY |
| | 43 | b.id, b.user_id, b.name, b.created_at, b.total_price |
| | 44 | ORDER BY |
| | 45 | COALESCE(AVG(rb.value::float), 0) DESC; |
| | 46 | }}} |