masaruk Logo

Trips & Bookings API

Trip management and booking operations endpoints

1. Purpose

This document defines the Trips and Bookings API endpoints for:

  • B2C Web & Mobile (trip browsing, booking creation)
  • Provider Portal (trip management)
  • Admin Panel (booking oversight)

All endpoints follow the conventions in api-principles-and-versioning.md.

3. Trips API

3.1 List Trips (Public)

GET/api/v1/trips

Auth: Not required (public endpoint)

Query Parameters
ParameterTypeDescription
typestringFilter by trip type: UMRAH / TOURISM
statusstringDefault: ACTIVE only (B2C)
pageintegerPage number (default: 1)
per_pageintegerItems per page (default: 20, max: 100)
sortstringSort field (e.g., -created_at, price)

3.2 Get Trip Details (Public)

GET/api/v1/trips/{id}

Auth: Not required (public endpoint)

Returns full trip details including hotel, bus, rest stops, itinerary, and images.

3.3 Create Trip (Provider)

POST/api/v1/provider/trips

Auth: Bearer token required

Roles: PROVIDER_ADMIN, PROVIDER_STAFF

Validation Rules
  • departure_date must be < return_date
  • days_count and nights_count must be > 0
  • max_capacity must be > 0
  • hotel_id must reference an ACTIVE hotel owned by the same provider
  • bus_id must reference an ACTIVE bus (not UNDER_MAINTENANCE) owned by the same provider

3.4 Update Trip (Provider)

PUT/api/v1/provider/trips/{id}

Auth: Bearer token required

Roles: PROVIDER_ADMIN, PROVIDER_STAFF

Restrictions
  • Cannot reduce max_capacity below current bookings count
  • Cannot change type if bookings exist
  • Cannot assign a bus with status UNDER_MAINTENANCE

3.5 Delete Trip (Provider)

DELETE/api/v1/provider/trips/{id}

Auth: Bearer token required

Roles: PROVIDER_ADMIN

Behavior
  • If no bookings exist: hard delete allowed
  • If bookings exist: status changes to CANCELLED, trip hidden from B2C

3.6 Activate/Deactivate Trip (Provider)

POSTPOST /api/v1/provider/trips/{id}/activate
POSTPOST /api/v1/provider/trips/{id}/deactivate

Auth: Bearer token required

Roles: PROVIDER_ADMIN, PROVIDER_STAFF

Activation Requirements
  • Hotel selected (ACTIVE)
  • Bus selected (ACTIVE)
  • At least one image
  • Valid dates (future)
  • Valid capacity (> 0)

4. Bookings API

4.1 Create Booking (Customer)

POST/api/v1/bookings

Auth: Bearer token required

Roles: CUSTOMER / END_USER

Booking status is PENDING until payment is completed. See payments-and-financials-api.md for payment flow.

4.2 Get My Bookings (Customer)

GET/api/v1/bookings/my

Auth: Bearer token required

Roles: CUSTOMER / END_USER

ParameterTypeDescription
statusstringFilter: CONFIRMED, PENDING, CANCELLED
upcomingbooleanIf true, return only future trips
completedbooleanIf true, return only past trips

4.3 Get Booking Details (Customer)

GET/api/v1/bookings/{id}

Auth: Bearer token required

Roles: CUSTOMER / END_USER

Additional: user_id must match booking.user_id

4.4 Cancel Booking (Customer)

POST/api/v1/bookings/{id}/cancel

Auth: Bearer token required

Roles: CUSTOMER / END_USER

Additional: user_id must match booking.user_id

Pre-conditions
  • Booking status = CONFIRMED
  • Trip departure_date > today
Refund Policy
Time Before TripRefund %
Before 30 days90%
Before 15 days70%
Before 7 days50%
Less than 7 days0%

4.5 List Bookings (Admin)

GET/api/v1/admin/bookings

Auth: Bearer token required

Roles: ADMIN, SUPER_ADMIN, SUPPORT_AGENT

ParameterTypeDescription
searchstringSearch by booking reference, customer name, phone
statusstringFilter by status
trip_idintegerFilter by trip
provider_idintegerFilter by provider
from_datedateFilter from date
to_datedateFilter to date

4.6 Get Booking Details (Admin)

GET/api/v1/admin/bookings/{id}

Auth: Bearer token required

Roles: ADMIN, SUPER_ADMIN, SUPPORT_AGENT

Full booking details including all passengers and payment info

4.7 Update Booking Status (Admin)

PATCH/api/v1/admin/bookings/{id}/status

Auth: Bearer token required

Roles: ADMIN, SUPER_ADMIN

4.8 List Bookings (Provider)

GET/api/v1/provider/bookings

Auth: Bearer token required

Roles: PROVIDER_ADMIN, PROVIDER_STAFF

Results are scoped to bookings for trips owned by the authenticated provider.

5. Error Cases

5.1 Trip Errors

Error CodeHTTPDescription
TRIP_NOT_FOUND404Trip does not exist
TRIP_NOT_AVAILABLE400Trip is INACTIVE or CANCELLED
TRIP_SOLD_OUT409Trip has reached max capacity
TRIP_DATE_PASSED400Trip departure date has passed

5.2 Booking Errors

Error CodeHTTPDescription
BOOKING_NOT_FOUND404Booking does not exist
BOOKING_ALREADY_CANCELLED400Booking is already cancelled
BOOKING_CANNOT_CANCEL400Cancellation not allowed (trip started)
BOOKING_ACCESS_DENIED403User does not own this booking
DUPLICATE_PASSENGER_ID422Same national_id repeated

6. Status Enums

6.1 Trip Status

Enum ValueArabic UIDescription
ACTIVEنشطةVisible and bookable
INACTIVEغير نشطةHidden from B2C
CANCELLEDملغاهNot bookable
COMPLETEDمنتهيةEnd date passed (derived)

6.2 Booking Status

Enum ValueArabic UIDescription
PENDINGقيد التنفيذInitial state, awaiting payment
CONFIRMEDمؤكدةPayment completed
CANCELLEDملغاهBooking cancelled
COMPLETEDمكتملةTrip finished (derived)
UPCOMINGقادمةTrip in future (derived)

7. Cross-References

Related Entities:

Trip, TripItineraryDay, Booking, BookingPassenger, User, Provider, Hotel, Bus, RestStop, PaymentTransaction

Related Screens:

الرحلات, تفاصيل الرحلة, مسار الحجز, حجوزاتي, إدارة الرحلات, إدارة الحجوزات

Related APIs:

payments-and-financials-api.md, providers-and-resources-api.md, auth-and-users-api.md

Related Business Rules:

Trip lifecycle, Booking lifecycle, Refund policy

Related Roles:

CUSTOMER, PROVIDER_ADMIN, PROVIDER_STAFF, ADMIN, SUPER_ADMIN, SUPPORT_AGENT