Skip to main content

Add Favorite POI

Add a POI to the user’s favorites list.

Authentication

Requires JWT authentication. Users can manage their own favorites, or admins can manage any user’s favorites.
Authorization: Bearer <jwt_token>

Path Parameters

user_id
string
required
The user’s unique identifier (MongoDB ObjectId)

Query Parameters

poi_id
string
required
The POI identifier to add to favorites

Response

message
string
Success confirmation message
{
  "message": "POI agregado a favoritos"
}

Code Examples

curl -X POST "https://api.tesisrutas.com/usuarios/507f1f77bcf86cd799439011/favoritosPOI?poi_id=507f191e810c19729de860ea" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Error Responses

403
error
Forbidden - User attempting to modify another user’s favorites
{
  "detail": "No puedes modificar este usuario"
}
400
error
Bad Request - Failed to add favorite
{
  "detail": "No se pudo agregar el POI a favoritos."
}

Remove Favorite POI

Remove a POI from the user’s favorites list.

Authentication

Requires JWT authentication. Users can manage their own favorites, or admins can manage any user’s favorites.
Authorization: Bearer <jwt_token>

Path Parameters

user_id
string
required
The user’s unique identifier (MongoDB ObjectId)
poi_id
string
required
The POI identifier to remove from favorites

Response

message
string
Success confirmation message
{
  "message": "POI eliminado de favoritos"
}

Code Examples

curl -X DELETE "https://api.tesisrutas.com/usuarios/507f1f77bcf86cd799439011/favoritosPOI/507f191e810c19729de860ea" \
  -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."

Error Responses

403
error
Forbidden - User attempting to modify another user’s favorites
{
  "detail": "No puedes modificar este usuario"
}
400
error
Bad Request - Failed to remove favorite
{
  "detail": "No se pudo eliminar el POI de favoritos."
}

Authorization Rules

  • Self-manage: Users can add/remove favorites from their own account
  • Admin-manage: Admins can manage any user’s favorites
  • Restricted: Users cannot modify other users’ favorites unless they are admins

Implementation Details

Add Favorite Source: src/infrastructure/api/routers/usuario_router.py:116-135 Remove Favorite Source: src/infrastructure/api/routers/usuario_router.py:137-156 These endpoints use MongoDB’s $addToSet and $pull operators to manage the favorites array:
  • $addToSet ensures no duplicate POIs are added
  • $pull removes the specified POI from the array
The favorites are stored as an array of POI IDs in the user document, allowing quick lookups and personalized recommendations.

Build docs developers (and LLMs) love