Overview
The Favorite Tours API allows tourists to save their favorite tours for easy reference and future booking. This resource uses a composite key consisting oftouristId and tourId to uniquely identify favorite relationships.
Composite Key Structure
Favorite tour records are identified by a composite primary key:- touristId: The ID of the tourist user
- tourId: The ID of the tour
Endpoints
Create Favorite Tour
The ID of the tourist user marking the tour as favorite
The ID of the tour being marked as favorite
Optional timestamp. If not provided, the server will set it automatically.
The ID of the tourist user
The ID of the tour
Timestamp when the favorite was created
Get All Favorite Tours
Array of favorite tour objects
Get Favorite Tour by Composite Key
The ID of the tourist user
The ID of the tour
The ID of the tourist user
The ID of the tour
Timestamp when the favorite was created
Update Favorite Tour
The ID of the tourist user
The ID of the tour
Updated timestamp for when the favorite was created
The ID of the tourist user
The ID of the tour
Updated timestamp
Delete Favorite Tour
The ID of the tourist user
The ID of the tour
No content returned on successful deletion
Usage Examples
Check if Tour is Favorited
To check if a specific tour is in a tourist’s favorites:- If the relationship exists, you’ll receive a 200 response with the favorite data
- If it doesn’t exist, you’ll receive a 404 error
Get Tourist’s Favorite Tours
To retrieve all tours favorited by a specific tourist, filter the results from the get all endpoint:Get Tourists Who Favorited a Tour
To see which tourists have favorited a specific tour (useful for analytics):Toggle Favorite Status
To implement a toggle favorite feature in your application:- First, check if the tour is already favorited (GET request)
- If it exists (200 response), delete it (DELETE request)
- If it doesn’t exist (404 response), create it (POST request)
Relationships
The FavoriteTour entity maintains relationships with:- Tourist User: References the user table via
touristId→user_id - Tour: References the tours table via
tourId→tour_id
Use Cases
- Wishlist: Tourists can build a wishlist of tours they’re interested in
- Quick Access: Easy retrieval of saved tours for comparison and booking
- Recommendations: Analyze favorite patterns to improve tour recommendations
- Marketing: Notify tourists about updates or deals on their favorited tours