| | 37 | 4. The user clicks on one of the build cards and a popup with the build details is displayed |
| | 38 | |
| | 39 | {{{ |
| | 40 | BEGIN; |
| | 41 | |
| | 42 | SELECT |
| | 43 | b.id, |
| | 44 | b.user_id, |
| | 45 | b.name, |
| | 46 | b.created_at, |
| | 47 | b.description, |
| | 48 | b.total_price, |
| | 49 | b.is_approved, |
| | 50 | u.username AS "creator" |
| | 51 | FROM build AS b |
| | 52 | INNER JOIN users AS u |
| | 53 | ON b.user_id = u.id |
| | 54 | WHERE b.id = $buildId |
| | 55 | LIMIT 1; |
| | 56 | |
| | 57 | SELECT |
| | 58 | bc.component_id AS "componentId", |
| | 59 | c.* AS "component" |
| | 60 | FROM build_component AS bc |
| | 61 | INNER JOIN components AS c |
| | 62 | ON bc.component_id = c.id |
| | 63 | WHERE bc.build_id = $buildId; |
| | 64 | |
| | 65 | SELECT |
| | 66 | u.username, |
| | 67 | r.content, |
| | 68 | r.created_at |
| | 69 | FROM review AS r |
| | 70 | INNER JOIN users AS u |
| | 71 | ON r.user_id = u.id |
| | 72 | WHERE r.build_id = $buildId |
| | 73 | ORDER BY r.created_at DESC; |
| | 74 | |
| | 75 | SELECT |
| | 76 | COALESCE(AVG(rb.value::float), 0) AS "averageRating", |
| | 77 | COUNT(rb.value) AS "ratingCount" |
| | 78 | FROM rating_build AS rb |
| | 79 | WHERE rb.build_id = $buildId; |
| | 80 | |
| | 81 | SELECT value |
| | 82 | FROM rating_build |
| | 83 | WHERE build_id = $buildId AND user_id = $userId |
| | 84 | LIMIT 1; |
| | 85 | |
| | 86 | SELECT 1 |
| | 87 | FROM favorite_build |
| | 88 | WHERE build_id = $buildId AND user_id = $userId |
| | 89 | LIMIT 1; |
| | 90 | |
| | 91 | SELECT content |
| | 92 | FROM review |
| | 93 | WHERE build_id = $buildId AND user_id = $userId |
| | 94 | LIMIT 1; |
| | 95 | |
| | 96 | COMMIT; |