Skip to main content

Overview

The Favorite Guides API allows tourists to save their favorite guides for easy access and follow-up. This resource uses a composite key consisting of touristId and guideId to uniquely identify favorite relationships.

Composite Key Structure

Favorite guide records are identified by a composite primary key:
  • touristId: The ID of the tourist user
  • guideId: The ID of the guide user
This composite key ensures that each tourist-guide pair can only exist once in the system.

Endpoints

Create Favorite Guide

curl -X POST http://localhost:8080/api/favorite_guides \
  -H "Content-Type: application/json" \
  -d '{
    "touristId": 123,
    "guideId": 456
  }'
Adds a guide to a tourist’s favorites list.
touristId
Long
required
The ID of the tourist user marking the guide as favorite
guideId
Long
required
The ID of the guide user being marked as favorite
createdAt
datetime
Optional timestamp. If not provided, the server will set it automatically.
touristId
Long
The ID of the tourist user
guideId
Long
The ID of the guide user
createdAt
datetime
Timestamp when the favorite was created

Get All Favorite Guides

curl http://localhost:8080/api/favorite_guides
Retrieves a list of all favorite guide relationships.
favorites
array
Array of favorite guide objects

Get Favorite Guide by Composite Key

curl http://localhost:8080/api/favorite_guides/123/456
Retrieves a specific favorite guide relationship using the composite key.
touristId
Long
required
The ID of the tourist user
guideId
Long
required
The ID of the guide user
touristId
Long
The ID of the tourist user
guideId
Long
The ID of the guide user
createdAt
datetime
Timestamp when the favorite was created

Update Favorite Guide

curl -X PUT http://localhost:8080/api/favorite_guides/123/456 \
  -H "Content-Type: application/json" \
  -d '{
    "createdAt": "2024-03-15T10:30:00"
  }'
Updates an existing favorite guide relationship. Typically used to update metadata like the creation timestamp.
touristId
Long
required
The ID of the tourist user
guideId
Long
required
The ID of the guide user
createdAt
datetime
Updated timestamp for when the favorite was created
touristId
Long
The ID of the tourist user
guideId
Long
The ID of the guide user
createdAt
datetime
Updated timestamp

Delete Favorite Guide

curl -X DELETE http://localhost:8080/api/favorite_guides/123/456
Removes a guide from a tourist’s favorites list using the composite key.
touristId
Long
required
The ID of the tourist user
guideId
Long
required
The ID of the guide user
status
204
No content returned on successful deletion

Usage Examples

Check if Guide is Favorited

To check if a specific guide is in a tourist’s favorites:
curl http://localhost:8080/api/favorite_guides/123/456
  • 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 Guides

To retrieve all guides favorited by a specific tourist, filter the results from the get all endpoint:
curl http://localhost:8080/api/favorite_guides | jq '.[] | select(.touristId == 123)'

Get Guides Who Favorited a User

To see which tourists have favorited a specific guide:
curl http://localhost:8080/api/favorite_guides | jq '.[] | select(.guideId == 456)'

Relationships

The FavoriteGuide entity maintains relationships with:
  • Tourist User: References the user table via touristIduser_id
  • Guide User: References the user table via guideIduser_id
Both IDs must reference valid users in the system.

Build docs developers (and LLMs) love