| | 1 | = Use-case 0003 - Approve or reject reservation = |
| | 2 | |
| | 3 | '''Initiating actor:''' |
| | 4 | |
| | 5 | Reservation Approver |
| | 6 | |
| | 7 | '''Other actors:''' |
| | 8 | |
| | 9 | Room Requester |
| | 10 | |
| | 11 | '''Description of the use-case goals:''' |
| | 12 | |
| | 13 | The goal of this use case is to allow a reservation approver to review pending reservation requests and record an approval or rejection decision. The system displays pending reservations together with requester, room, and equipment details. The approver then chooses a decision. The database is modified by updating the reservation status and inserting a corresponding approval record in the approvals table. |
| | 14 | |
| | 15 | '''Scenario:''' |
| | 16 | |
| | 17 | The Reservation Approver opens the list of pending reservations. |
| | 18 | The system loads pending reservation requests from the database. |
| | 19 | The system displays reservation details, including requester, room, date, time, requested equipment, and requested quantities. |
| | 20 | The Reservation Approver selects one reservation. |
| | 21 | The Reservation Approver chooses whether to approve or reject the reservation and enters an optional note. |
| | 22 | The system updates the reservation status. |
| | 23 | The system inserts the approval decision in the approvals table. |
| | 24 | The system displays the final decision for the selected reservation. |
| | 25 | |
| | 26 | '''SQL commands used by the system:''' |
| | 27 | |
| | 28 | List all pending reservations: |
| | 29 | |
| | 30 | {{{ |
| | 31 | SELECT |
| | 32 | res.reservation_id, |
| | 33 | res.reservation_date, |
| | 34 | res.start_time, |
| | 35 | res.end_time, |
| | 36 | res.status, |
| | 37 | u.full_name AS requester_name, |
| | 38 | r.room_code, |
| | 39 | e.name AS requested_equipment, |
| | 40 | req.requested_quantity |
| | 41 | FROM project.reservations res |
| | 42 | JOIN project.users u |
| | 43 | ON u.user_id = res.user_id |
| | 44 | LEFT JOIN project.rooms r |
| | 45 | ON r.room_id = res.room_id |
| | 46 | LEFT JOIN project.reservation_equipment req |
| | 47 | ON req.reservation_id = res.reservation_id |
| | 48 | LEFT JOIN project.equipment e |
| | 49 | ON e.equipment_id = req.equipment_id |
| | 50 | WHERE res.status = 'pending' |
| | 51 | ORDER BY res.reservation_date, res.start_time, res.reservation_id; |
| | 52 | }}} |
| | 53 | |
| | 54 | Approve a pending reservation and create an approval record: |
| | 55 | |
| | 56 | {{{ |
| | 57 | BEGIN; |
| | 58 | |
| | 59 | UPDATE project.reservations |
| | 60 | SET status = 'approved' |
| | 61 | WHERE reservation_id = 1 |
| | 62 | AND status = 'pending'; |
| | 63 | |
| | 64 | INSERT INTO project.approvals ( |
| | 65 | reservation_id, |
| | 66 | approver_id, |
| | 67 | decision, |
| | 68 | decision_time, |
| | 69 | note |
| | 70 | ) |
| | 71 | SELECT |
| | 72 | 1, |
| | 73 | u.user_id, |
| | 74 | 'approved', |
| | 75 | CURRENT_TIMESTAMP, |
| | 76 | 'Approved after checking room and equipment availability.' |
| | 77 | FROM project.users u |
| | 78 | WHERE u.username = 'approver1' |
| | 79 | AND NOT EXISTS ( |
| | 80 | SELECT 1 |
| | 81 | FROM project.approvals a |
| | 82 | WHERE a.reservation_id = 1 |
| | 83 | ); |
| | 84 | |
| | 85 | COMMIT; |
| | 86 | }}} |
| | 87 | |
| | 88 | Show the final approval decision: |
| | 89 | |
| | 90 | {{{ |
| | 91 | SELECT |
| | 92 | res.reservation_id, |
| | 93 | res.status, |
| | 94 | a.decision, |
| | 95 | a.decision_time, |
| | 96 | a.note, |
| | 97 | approver.full_name AS approver_name |
| | 98 | FROM project.reservations res |
| | 99 | JOIN project.approvals a |
| | 100 | ON a.reservation_id = res.reservation_id |
| | 101 | JOIN project.users approver |
| | 102 | ON approver.user_id = a.approver_id |
| | 103 | WHERE res.reservation_id = 1; |
| | 104 | }}} |