| | 1 | == User opens dashboard == |
| | 2 | |
| | 3 | === Actors === |
| | 4 | Guest, User, Admin |
| | 5 | |
| | 6 | === Scenario === |
| | 7 | 1. The user clicks on the "COMPLETED BUILDS" button |
| | 8 | 2. A new page with all the completed and approved builds is displayed |
| | 9 | 3. The user can sort by creation date, price and search by name |
| | 10 | |
| | 11 | {{{ |
| | 12 | SELECT |
| | 13 | b.id, |
| | 14 | b.user_id, |
| | 15 | b.name, |
| | 16 | b.created_at, |
| | 17 | b.total_price, |
| | 18 | COALESCE(AVG(rb.value::float), 0) AS avgRating |
| | 19 | FROM build AS b |
| | 20 | LEFT JOIN rating_build AS rb |
| | 21 | ON b.id = rb.build_id |
| | 22 | WHERE |
| | 23 | b.is_approved = true |
| | 24 | AND b.name ILIKE ('%' || $q || '%') |
| | 25 | GROUP BY |
| | 26 | b.id, b.user_id, b.name, b.created_at, b.total_price |
| | 27 | ORDER BY |
| | 28 | CASE WHEN $sort = 'price_asc' THEN b.total_price END ASC, |
| | 29 | CASE WHEN $sort = 'price_desc' THEN b.total_price END DESC, |
| | 30 | CASE WHEN $sort = 'rating_desc' THEN COALESCE(AVG(rb.value::float), 0) END DESC, |
| | 31 | CASE WHEN $sort = 'oldest' THEN b.created_at END ASC, |
| | 32 | CASE WHEN $sort = 'newest' THEN b.created_at END DESC, |
| | 33 | b.created_at DESC |
| | 34 | LIMIT COALESCE($limit, 100); |
| | 35 | |
| | 36 | }}} |