| | 1 | == Add component to build == |
| | 2 | |
| | 3 | === Actors === |
| | 4 | |
| | 5 | Admin |
| | 6 | |
| | 7 | === Scenario === |
| | 8 | |
| | 9 | 1. In the admin dashboard, there is a button labeled 'Add Component' with which the admin can add any component needed. The labels and text fields are populated by back-end logic, so it's as seamless as possible. |
| | 10 | |
| | 11 | [[Image(component.png, width=800, height=420)]] |
| | 12 | |
| | 13 | 2. When the button is clicked, a popup appears which has some basic information, but one of the fields is a dropdown with all the component types. The admins can choose which component they want and the fields populate. |
| | 14 | |
| | 15 | [[Image(componentpopup.png, width=800, height=420)]] |
| | 16 | [[Image(componentdropdown.png, width=800, height=420)]] |
| | 17 | |
| | 18 | 3. When the admin selects a cpu, for example, it automatically populates the needed fields and then he can enter the information. |
| | 19 | |
| | 20 | [[Image(populatedfields.png, width=800, height=420)]] |
| | 21 | |
| | 22 | 4. After the admin clicks create component, the popup disappears and if we check popup with all the cpus we can see that the new cpu is inserted successfully. |
| | 23 | |
| | 24 | [[Image(newComponent.png, width=800, height=420)]] |
| | 25 | |
| | 26 | {{{ |
| | 27 | BEGIN; |
| | 28 | |
| | 29 | SELECT * |
| | 30 | FROM build |
| | 31 | WHERE id = $buildId |
| | 32 | AND user_id = $userId |
| | 33 | LIMIT 1; |
| | 34 | |
| | 35 | SELECT * |
| | 36 | FROM build_component |
| | 37 | WHERE build_id = $buildId |
| | 38 | AND component_id = $componentId |
| | 39 | LIMIT 1; |
| | 40 | |
| | 41 | INSERT INTO build_component (build_id, component_id) |
| | 42 | VALUES ($buildId, $componentId); |
| | 43 | |
| | 44 | SELECT c.price |
| | 45 | FROM build_component bc |
| | 46 | JOIN components c ON c.id = bc.component_id |
| | 47 | WHERE bc.build_id = $buildId; |
| | 48 | |
| | 49 | UPDATE build |
| | 50 | SET total_price = ( |
| | 51 | SELECT COALESCE(ROUND(SUM(c.price), 2), 0) |
| | 52 | FROM build_component bc |
| | 53 | JOIN components c ON c.id = bc.component_id |
| | 54 | WHERE bc.build_id = $buildId |
| | 55 | ) |
| | 56 | WHERE id = $buildId; |
| | 57 | |
| | 58 | COMMIT; |
| | 59 | }}} |
| | 60 | |
| | 61 | [[Image(addedComponent.png, width=800, height=420)]] |