| | 1 | = Use-case 0012 Implementation - Book Appointment for Viewing |
| | 2 | |
| | 3 | '''Initiating actor:''' Client |
| | 4 | |
| | 5 | '''Other actors:''' Agent |
| | 6 | |
| | 7 | '''Description:''' |
| | 8 | |
| | 9 | A client books an appointment to physically view an apartment unit. This reserves a timeslot with an agent and marks the slot as booked. |
| | 10 | |
| | 11 | == Scenario |
| | 12 | |
| | 13 | === Step 1 |
| | 14 | |
| | 15 | '''User action:''' Client navigates to booking page for unit 101 in Golden Tower. |
| | 16 | |
| | 17 | '''Screenshot:''' [Image] |
| | 18 | |
| | 19 | '''System action:''' System displays available agents and timeslots. |
| | 20 | |
| | 21 | '''Query: ''' |
| | 22 | {{{ |
| | 23 | SET search_path TO project; |
| | 24 | |
| | 25 | SELECT |
| | 26 | a.agent_id, |
| | 27 | a.name AS agent_name, |
| | 28 | a.email, |
| | 29 | t.timeslot_id, |
| | 30 | t.date, |
| | 31 | t.time_start, |
| | 32 | t.time_end |
| | 33 | FROM agent a |
| | 34 | JOIN timeslot t ON a.agent_id = t.agent_id |
| | 35 | WHERE t. status = 'Available' |
| | 36 | AND t.date >= CURRENT_DATE |
| | 37 | ORDER BY a.name, t.date, t.time_start; |
| | 38 | }}} |
| | 39 | |
| | 40 | === Step 2 |
| | 41 | |
| | 42 | '''User action:''' Client selects agent "Bojana" and timeslot "June 1, 2026 at 11:00 AM". |
| | 43 | |
| | 44 | '''Screenshot:''' [Image] |
| | 45 | |
| | 46 | === Step 3 |
| | 47 | |
| | 48 | '''User action: ''' Client enters their information: Luka Krstikj, lukakr@gmail.com, +389 70 123 456. |
| | 49 | |
| | 50 | '''Screenshot:''' [Image] |
| | 51 | |
| | 52 | === Step 4 |
| | 53 | |
| | 54 | '''User action:''' Client clicks "Confirm Appointment". |
| | 55 | |
| | 56 | '''Screenshot:''' [Image] |
| | 57 | |
| | 58 | '''System action:''' System verifies timeslot is still available. |
| | 59 | |
| | 60 | '''Query:''' |
| | 61 | {{{ |
| | 62 | SET search_path TO project; |
| | 63 | |
| | 64 | SELECT status |
| | 65 | FROM timeslot |
| | 66 | WHERE timeslot_id = ( |
| | 67 | SELECT timeslot_id FROM timeslot |
| | 68 | WHERE date = '2026-06-01' |
| | 69 | AND time_start = '11:00:00' |
| | 70 | AND agent_id = (SELECT agent_id FROM agent WHERE name = 'Bojana') |
| | 71 | ); |
| | 72 | }}} |
| | 73 | |
| | 74 | === Step 5 |
| | 75 | |
| | 76 | '''System action:''' System creates client record if needed. |
| | 77 | |
| | 78 | '''Query:''' |
| | 79 | {{{ |
| | 80 | SET search_path TO project; |
| | 81 | |
| | 82 | INSERT INTO client (name, email, phone) |
| | 83 | VALUES ('Luka Krstikj', 'lukakr@gmail.com', '+389 70 123 456') |
| | 84 | ON CONFLICT (email) DO UPDATE |
| | 85 | SET name = 'Luka Krstikj', phone = '+389 70 123 456' |
| | 86 | RETURNING client_id; |
| | 87 | }}} |
| | 88 | |
| | 89 | === Step 6 |
| | 90 | |
| | 91 | '''System action:''' System creates the appointment. |
| | 92 | |
| | 93 | '''Query:''' |
| | 94 | {{{ |
| | 95 | SET search_path TO project; |
| | 96 | |
| | 97 | INSERT INTO appointment (status, client_id, unit_id, timeslot_id, agent_id) |
| | 98 | VALUES ( |
| | 99 | 'Scheduled', |
| | 100 | (SELECT client_id FROM client WHERE email = 'lukakr@gmail.com'), |
| | 101 | (SELECT unit_id FROM unit WHERE unit_number = '101' |
| | 102 | AND floor_id = (SELECT floor_id FROM floor |
| | 103 | WHERE building_id = (SELECT building_id FROM building WHERE name = 'Golden Tower') |
| | 104 | AND floor_number = 1)), |
| | 105 | (SELECT timeslot_id FROM timeslot |
| | 106 | WHERE date = '2026-06-01' |
| | 107 | AND time_start = '11:00:00' |
| | 108 | AND agent_id = (SELECT agent_id FROM agent WHERE name = 'Bojana')), |
| | 109 | (SELECT agent_id FROM agent WHERE name = 'Bojana') |
| | 110 | ) |
| | 111 | RETURNING appointment_id; |
| | 112 | }}} |
| | 113 | |
| | 114 | === Step 7 |
| | 115 | |
| | 116 | '''System action:''' System updates timeslot to booked. |
| | 117 | |
| | 118 | '''Query:''' |
| | 119 | {{{ |
| | 120 | SET search_path TO project; |
| | 121 | |
| | 122 | UPDATE timeslot |
| | 123 | SET status = 'Booked' |
| | 124 | WHERE timeslot_id = (SELECT timeslot_id FROM timeslot |
| | 125 | WHERE date = '2026-06-01' |
| | 126 | AND time_start = '11:00:00' |
| | 127 | AND agent_id = (SELECT agent_id FROM agent WHERE name = 'Bojana')); |
| | 128 | }}} |
| | 129 | |
| | 130 | === Step 8 |
| | 131 | |
| | 132 | '''System action: ''' System displays confirmation with appointment details. |
| | 133 | |
| | 134 | '''Query:''' |
| | 135 | {{{ |
| | 136 | SET search_path TO project; |
| | 137 | |
| | 138 | SELECT |
| | 139 | ap.appointment_id, |
| | 140 | c.name AS client_name, |
| | 141 | c.email AS client_email, |
| | 142 | c. phone AS client_phone, |
| | 143 | u.unit_number, |
| | 144 | b.name AS building_name, |
| | 145 | f.floor_number, |
| | 146 | t.date, |
| | 147 | t.time_start, |
| | 148 | t.time_end, |
| | 149 | a.name AS agent_name, |
| | 150 | a.email AS agent_email |
| | 151 | FROM appointment ap |
| | 152 | JOIN client c ON ap.client_id = c. client_id |
| | 153 | JOIN unit u ON ap.unit_id = u. unit_id |
| | 154 | JOIN floor f ON u.floor_id = f. floor_id |
| | 155 | JOIN building b ON f.building_id = b. building_id |
| | 156 | JOIN timeslot t ON ap.timeslot_id = t.timeslot_id |
| | 157 | JOIN agent a ON ap. agent_id = a.agent_id |
| | 158 | WHERE ap.appointment_id = (SELECT appointment_id FROM appointment |
| | 159 | WHERE client_id = (SELECT client_id FROM client WHERE email = 'lukakr@gmail.com') |
| | 160 | ORDER BY appointment_id DESC LIMIT 1); |
| | 161 | }}} |
| | 162 | |
| | 163 | '''Screenshot:''' [Image] |