|
| 1 | +# 🎫 Booking Modifications Feature - Implementation Guide |
| 2 | + |
| 3 | +## 📋 Overview |
| 4 | + |
| 5 | +The Booking Modifications feature allows users to modify their existing bookings without cancelling and rebooking. This includes: |
| 6 | +- **Date Changes**: Change journey date (and optionally train) |
| 7 | +- **Seat Upgrades/Downgrades**: Change seat class (AC, Sleeper, etc.) |
| 8 | +- **Passenger Modifications**: Add or remove passengers from booking |
| 9 | +- **Route Changes**: Change source/destination stations |
| 10 | + |
| 11 | +--- |
| 12 | + |
| 13 | +## 🚀 Features Implemented |
| 14 | + |
| 15 | +### 1. **Date Change Modification** |
| 16 | +- Change journey date for existing booking |
| 17 | +- Optionally change to a different train |
| 18 | +- Automatic fare recalculation (when Train Service integration is added) |
| 19 | +- Time-based modification charges |
| 20 | + |
| 21 | +**API Endpoint**: `PUT /api/bookings/{id}/modify-date` |
| 22 | + |
| 23 | +**Request Body**: |
| 24 | +```json |
| 25 | +{ |
| 26 | + "newJourneyDate": "2025-12-25T10:00:00", |
| 27 | + "newTrainId": 123, // Optional |
| 28 | + "reason": "Change of plans" // Optional |
| 29 | +} |
| 30 | +``` |
| 31 | + |
| 32 | +### 2. **Seat Upgrade/Downgrade** |
| 33 | +- Upgrade or downgrade seat class |
| 34 | +- Automatic fare difference calculation |
| 35 | +- Modification charges based on time until journey |
| 36 | + |
| 37 | +**API Endpoint**: `PUT /api/bookings/{id}/upgrade-seat` |
| 38 | + |
| 39 | +**Request Body**: |
| 40 | +```json |
| 41 | +{ |
| 42 | + "newSeatClass": "2AC", |
| 43 | + "newFare": 2500.00, |
| 44 | + "newSeatNumber": "A1", // Optional |
| 45 | + "reason": "Want better comfort" |
| 46 | +} |
| 47 | +``` |
| 48 | + |
| 49 | +### 3. **Passenger Modification** |
| 50 | +- Add new passengers to booking |
| 51 | +- Remove passengers from booking |
| 52 | +- Automatic fare adjustment for passenger changes |
| 53 | + |
| 54 | +**API Endpoint**: `PUT /api/bookings/{id}/modify-passengers` |
| 55 | + |
| 56 | +**Request Body**: |
| 57 | +```json |
| 58 | +{ |
| 59 | + "passengersToAdd": [ |
| 60 | + { |
| 61 | + "name": "John Doe", |
| 62 | + "age": 30, |
| 63 | + "gender": "MALE", |
| 64 | + "seatNumber": "A2", |
| 65 | + "idProofType": "AADHAAR", |
| 66 | + "idProofNumber": "123456789012" |
| 67 | + } |
| 68 | + ], |
| 69 | + "passengerIdsToRemove": [5, 6], // Optional |
| 70 | + "additionalFare": 1200.00, |
| 71 | + "reason": "Adding family member" |
| 72 | +} |
| 73 | +``` |
| 74 | + |
| 75 | +### 4. **Route Change** |
| 76 | +- Change source and/or destination stations |
| 77 | +- Optionally change to a different train |
| 78 | +- Automatic fare recalculation |
| 79 | + |
| 80 | +**API Endpoint**: `PUT /api/bookings/{id}/change-route` |
| 81 | + |
| 82 | +**Request Body**: |
| 83 | +```json |
| 84 | +{ |
| 85 | + "newSourceStation": "Mumbai Central", |
| 86 | + "newDestinationStation": "Delhi", |
| 87 | + "newTrainId": 456, // Optional |
| 88 | + "newFare": 3000.00, |
| 89 | + "reason": "Change of destination" |
| 90 | +} |
| 91 | +``` |
| 92 | + |
| 93 | +### 5. **Modification Options** |
| 94 | +- Get available modification options for a booking |
| 95 | +- View modification charges before proceeding |
| 96 | +- Check what modifications are allowed based on booking status and time |
| 97 | + |
| 98 | +**API Endpoint**: `GET /api/bookings/{id}/modification-options` |
| 99 | + |
| 100 | +**Response**: |
| 101 | +```json |
| 102 | +{ |
| 103 | + "bookingId": 123, |
| 104 | + "currentStatus": "CONFIRMED", |
| 105 | + "canModifyDate": true, |
| 106 | + "canUpgradeSeat": true, |
| 107 | + "canChangeRoute": false, |
| 108 | + "canModifyPassengers": true, |
| 109 | + "modificationCharges": { |
| 110 | + "dateChange": 200.00, |
| 111 | + "seatUpgrade": 100.00, |
| 112 | + "routeChange": 300.00, |
| 113 | + "passengerModification": 150.00 |
| 114 | + }, |
| 115 | + "lastModificationDate": null, |
| 116 | + "modificationCount": 0 |
| 117 | +} |
| 118 | +``` |
| 119 | + |
| 120 | +--- |
| 121 | + |
| 122 | +## 💰 Modification Charges |
| 123 | + |
| 124 | +### Charge Calculation Rules |
| 125 | + |
| 126 | +1. **Base Charges**: |
| 127 | + - Date Change: ₹200 |
| 128 | + - Seat Upgrade: ₹100 |
| 129 | + - Route Change: ₹300 |
| 130 | + - Passenger Modification: ₹150 per passenger |
| 131 | + |
| 132 | +2. **Time-based Multipliers**: |
| 133 | + - **Same day (< 24 hours)**: 2x base charge |
| 134 | + - **Within 48 hours**: 1.5x base charge |
| 135 | + - **Within 72 hours**: 1.2x base charge |
| 136 | + - **More than 72 hours**: Base charge |
| 137 | + |
| 138 | +3. **Special Rules**: |
| 139 | + - Seat downgrade: 50% of base charge |
| 140 | + - Multiple modifications: Charges are cumulative |
| 141 | + |
| 142 | +### Example Calculations |
| 143 | + |
| 144 | +**Date Change (48 hours before journey)**: |
| 145 | +- Base: ₹200 |
| 146 | +- Multiplier: 1.5x |
| 147 | +- **Total: ₹300** |
| 148 | + |
| 149 | +**Seat Upgrade (Same day)**: |
| 150 | +- Base: ₹100 |
| 151 | +- Multiplier: 2x |
| 152 | +- **Total: ₹200** |
| 153 | + |
| 154 | +--- |
| 155 | + |
| 156 | +## ✅ Business Rules |
| 157 | + |
| 158 | +### Modification Eligibility |
| 159 | + |
| 160 | +1. **Booking Status**: Only `CONFIRMED` or `PENDING` bookings can be modified |
| 161 | +2. **Time Restrictions**: |
| 162 | + - Date Change: Minimum 4 hours before journey |
| 163 | + - Seat Upgrade: Minimum 2 hours before journey |
| 164 | + - Route Change: Minimum 6 hours before journey |
| 165 | + - Passenger Modification: Minimum 4 hours before journey |
| 166 | + |
| 167 | +3. **Validation**: |
| 168 | + - New journey date must be in the future |
| 169 | + - Cannot modify cancelled or completed bookings |
| 170 | + - Passenger IDs must exist in booking |
| 171 | + |
| 172 | +--- |
| 173 | + |
| 174 | +## 📁 File Structure |
| 175 | + |
| 176 | +``` |
| 177 | +irctc-booking-service/ |
| 178 | +├── src/main/java/com/irctc/booking/ |
| 179 | +│ ├── dto/ |
| 180 | +│ │ ├── BookingModificationRequest.java |
| 181 | +│ │ ├── DateChangeRequest.java |
| 182 | +│ │ ├── SeatUpgradeRequest.java |
| 183 | +│ │ ├── PassengerModificationRequest.java |
| 184 | +│ │ ├── RouteChangeRequest.java |
| 185 | +│ │ ├── ModificationOptionsResponse.java |
| 186 | +│ │ └── ModificationResponse.java |
| 187 | +│ ├── service/ |
| 188 | +│ │ ├── BookingModificationService.java |
| 189 | +│ │ └── ModificationChargeCalculator.java |
| 190 | +│ └── controller/ |
| 191 | +│ └── SimpleBookingController.java (updated with modification endpoints) |
| 192 | +``` |
| 193 | + |
| 194 | +--- |
| 195 | + |
| 196 | +## 🔧 Technical Implementation |
| 197 | + |
| 198 | +### Key Components |
| 199 | + |
| 200 | +1. **BookingModificationService**: |
| 201 | + - Handles all modification business logic |
| 202 | + - Validates modification eligibility |
| 203 | + - Updates booking entities |
| 204 | + - Returns modification responses |
| 205 | + |
| 206 | +2. **ModificationChargeCalculator**: |
| 207 | + - Calculates modification charges based on business rules |
| 208 | + - Time-based charge multipliers |
| 209 | + - Fare difference calculations |
| 210 | + |
| 211 | +3. **DTOs**: |
| 212 | + - Request DTOs for each modification type |
| 213 | + - Response DTOs with modification details |
| 214 | + - Options response for available modifications |
| 215 | + |
| 216 | +### Integration Points |
| 217 | + |
| 218 | +- **SimpleBookingService**: Used to fetch and update bookings |
| 219 | +- **TenantContext**: Multi-tenancy support |
| 220 | +- **Cache Management**: Automatic cache invalidation on modifications |
| 221 | +- **Audit Logging**: All modifications are audited via `@Auditable` annotation |
| 222 | + |
| 223 | +--- |
| 224 | + |
| 225 | +## 🧪 Testing |
| 226 | + |
| 227 | +### Test Scenarios |
| 228 | + |
| 229 | +1. **Date Change**: |
| 230 | + - ✅ Valid date change (more than 4 hours before) |
| 231 | + - ✅ Invalid date change (less than 4 hours before) |
| 232 | + - ✅ Date change with train change |
| 233 | + - ✅ Past date validation |
| 234 | + |
| 235 | +2. **Seat Upgrade**: |
| 236 | + - ✅ Valid seat upgrade |
| 237 | + - ✅ Seat downgrade |
| 238 | + - ✅ Same-day upgrade (higher charge) |
| 239 | + |
| 240 | +3. **Passenger Modification**: |
| 241 | + - ✅ Add passengers |
| 242 | + - ✅ Remove passengers |
| 243 | + - ✅ Add and remove simultaneously |
| 244 | + - ✅ Invalid passenger ID validation |
| 245 | + |
| 246 | +4. **Route Change**: |
| 247 | + - ✅ Valid route change |
| 248 | + - ✅ Route change with train change |
| 249 | + - ✅ Invalid route change (less than 6 hours) |
| 250 | + |
| 251 | +5. **Modification Options**: |
| 252 | + - ✅ Get options for modifiable booking |
| 253 | + - ✅ Get options for non-modifiable booking |
| 254 | + - ✅ Charge calculation accuracy |
| 255 | + |
| 256 | +### Example Test Request |
| 257 | + |
| 258 | +```bash |
| 259 | +# Get modification options |
| 260 | +curl -X GET http://localhost:8093/api/bookings/1/modification-options |
| 261 | + |
| 262 | +# Modify date |
| 263 | +curl -X PUT http://localhost:8093/api/bookings/1/modify-date \ |
| 264 | + -H "Content-Type: application/json" \ |
| 265 | + -d '{ |
| 266 | + "newJourneyDate": "2025-12-25T10:00:00", |
| 267 | + "reason": "Change of plans" |
| 268 | + }' |
| 269 | + |
| 270 | +# Upgrade seat |
| 271 | +curl -X PUT http://localhost:8093/api/bookings/1/upgrade-seat \ |
| 272 | + -H "Content-Type: application/json" \ |
| 273 | + -d '{ |
| 274 | + "newSeatClass": "2AC", |
| 275 | + "newFare": 2500.00 |
| 276 | + }' |
| 277 | +``` |
| 278 | + |
| 279 | +--- |
| 280 | + |
| 281 | +## 🔮 Future Enhancements |
| 282 | + |
| 283 | +1. **Train Service Integration**: |
| 284 | + - Fetch real-time fare from Train Service |
| 285 | + - Check seat availability before modification |
| 286 | + - Get alternative train options |
| 287 | + |
| 288 | +2. **Payment Integration**: |
| 289 | + - Automatic payment processing for fare differences |
| 290 | + - Refund processing for downgrades |
| 291 | + - Payment gateway integration |
| 292 | + |
| 293 | +3. **Notification Integration**: |
| 294 | + - Send modification confirmation emails/SMS |
| 295 | + - Notify about modification charges |
| 296 | + - Alert about refund processing |
| 297 | + |
| 298 | +4. **Modification History**: |
| 299 | + - Track all modifications in database |
| 300 | + - View modification history |
| 301 | + - Modification audit trail |
| 302 | + |
| 303 | +5. **Advanced Features**: |
| 304 | + - Partial modifications (modify only some passengers) |
| 305 | + - Modification scheduling (schedule modification for later) |
| 306 | + - Modification cancellation (undo modification) |
| 307 | + |
| 308 | +--- |
| 309 | + |
| 310 | +## 📊 API Summary |
| 311 | + |
| 312 | +| Endpoint | Method | Description | |
| 313 | +|----------|--------|-------------| |
| 314 | +| `/api/bookings/{id}/modification-options` | GET | Get available modification options | |
| 315 | +| `/api/bookings/{id}/modify-date` | PUT | Change booking date | |
| 316 | +| `/api/bookings/{id}/upgrade-seat` | PUT | Upgrade/downgrade seat class | |
| 317 | +| `/api/bookings/{id}/modify-passengers` | PUT | Add/remove passengers | |
| 318 | +| `/api/bookings/{id}/change-route` | PUT | Change source/destination | |
| 319 | + |
| 320 | +--- |
| 321 | + |
| 322 | +## ✅ Status |
| 323 | + |
| 324 | +- ✅ DTOs created |
| 325 | +- ✅ ModificationChargeCalculator implemented |
| 326 | +- ✅ BookingModificationService implemented |
| 327 | +- ✅ Controller endpoints added |
| 328 | +- ✅ Validation and error handling |
| 329 | +- ✅ Multi-tenancy support |
| 330 | +- ✅ Cache management |
| 331 | +- ✅ Audit logging |
| 332 | +- ⏳ Train Service integration (future) |
| 333 | +- ⏳ Payment integration (future) |
| 334 | +- ⏳ Notification integration (future) |
| 335 | + |
| 336 | +--- |
| 337 | + |
| 338 | +## 🎯 Next Steps |
| 339 | + |
| 340 | +1. **Integration Testing**: Test all modification endpoints |
| 341 | +2. **Train Service Client**: Create Feign client for fare calculation |
| 342 | +3. **Payment Service Integration**: Handle fare differences automatically |
| 343 | +4. **Notification Service**: Send modification confirmations |
| 344 | +5. **Database Migration**: Add modification history table (optional) |
| 345 | + |
| 346 | +--- |
| 347 | + |
| 348 | +**Feature Status**: ✅ **IMPLEMENTED AND READY FOR TESTING** |
| 349 | + |
0 commit comments