| | 1 | == Use-case 0004 - Create a Booking |
| | 2 | |
| | 3 | '''Initiating actor:''' Pet Owner |
| | 4 | |
| | 5 | '''Other actors:''' Pet Sitter |
| | 6 | |
| | 7 | '''Description:''' |
| | 8 | A Pet Owner finds a Pet Sitter they like and requests a booking. They must select the specific service they want. The system creates the booking and links the requested services using a secure database transaction. |
| | 9 | |
| | 10 | '''Scenario:''' |
| | 11 | 1. Pet Owner views the profile of a sitter (e.g., `sitter_filip`) and clicks "Request Booking". |
| | 12 | 2. System provides the specific services that this sitter offers to display in the booking form: |
| | 13 | {{{ |
| | 14 | #!sql |
| | 15 | SELECT s.service_id, s.type, s.description |
| | 16 | FROM services s |
| | 17 | JOIN sitter_services ss ON s.service_id = ss.service_id |
| | 18 | WHERE ss.sitter_id = (SELECT user_id FROM users WHERE username = 'sitter_filip'); |
| | 19 | }}} |
| | 20 | 3. Owner fills out the dates, location, selects the service, and submits. |
| | 21 | 4. System creates the booking with a 'PENDING' status and attaches the requested service simultaneously: |
| | 22 | {{{ |
| | 23 | #!sql |
| | 24 | BEGIN; |
| | 25 | |
| | 26 | WITH new_booking AS ( |
| | 27 | INSERT INTO bookings (status, date_from, date_to, address, owner_id, sitter_id) |
| | 28 | VALUES ( |
| | 29 | 'PENDING', '2026-06-10', '2026-06-12', 'ul. Partizanska br. 10', |
| | 30 | (SELECT user_id FROM users WHERE username = 'owner_bojan'), |
| | 31 | (SELECT user_id FROM users WHERE username = 'sitter_filip') |
| | 32 | ) |
| | 33 | RETURNING booking_id |
| | 34 | ) |
| | 35 | INSERT INTO booking_services (booking_id, service_id) |
| | 36 | SELECT nb.booking_id, (SELECT service_id FROM services WHERE type = 'Dog Walking') |
| | 37 | FROM new_booking nb; |
| | 38 | |
| | 39 | COMMIT; |
| | 40 | }}} |