API Endpoint Documentation - SagnikSaha01/CSC510-002-4 GitHub Wiki
API Endpoints
Restaurant Endpoints
GET /api/restaurants
Get all restaurants from the database.
Query Parameters:
None
Response:
[
{
"id": "uuid",
"name": "string",
"address": "string",
"banner_image_url": "string",
"created_at": "timestamp"
}
]
Status Codes:
- 200 — Success
- 404 — No restaurants found
- 500 — Server error
GET /api/restaurant/:restaurant_id
Get a single restaurant with its menu items.
Path Parameters: restaurant_id (UUID, required) — The restaurant's unique identifier
Response:
{
"id": "uuid",
"name": "string",
"address": "string",
"banner_image_url": "string",
"created_at": "timestamp",
"menu_items": [
{
"id": "uuid",
"restaurant_id": "uuid",
"name": "string",
"description": "string",
"category": "string",
"price": number,
"image_url": "string",
"created_at": "timestamp"
}
]
}
Status Codes:
- 200 — Success
- 404 — Restaurant not found
- 500 — Server error
POST /api/restaurants
Create a new restaurant with optional menu items.
Request Body:
{
"name": "string (required)",
"address": "string",
"banner_image_url": "string",
"menu_items": [
{
"name": "string",
"description": "string",
"category": "string",
"price": number,
"image_url": "string"
}
]
}
Response:
{
"id": "uuid",
"name": "string",
"address": "string",
"banner_image_url": "string",
"created_at": "timestamp",
"menu_items": [...]
}
Status Codes:
- 201 — Created
- 400 — Bad Request (missing required fields)
- 500 — Server error
Notes: Includes automatic rollback logic if menu items fail to save after restaurant creation. The created_at timestamp is automatically set by Supabase.
AI Service Endpoints
POST /api/recommendations
Get AI-powered restaurant or dish recommendations based on a user's mood.
Request Body:
{
"mood": "string (required)"
}
Response:
{
"recommendations": [
{
"id": number,
"title": "string",
"description": "string",
"image": "string (full URL)",
"price": number,
"distance": number,
"rating": number,
"category": "string"
}
]
}
Status Codes:
- 200 — Success
- 400 — Bad Request (missing mood)
- 404 — No restaurants available
- 500 — Server error
Notes: Uses OpenAI GPT-4o-mini model to analyze mood. Returns 8–10 personalized dish recommendations. AI considers comfort foods, healthy options, and adventurous choices. Temperature: 0.7, Max tokens: 2000
Cart Endpoints
POST /api/cart
Add an item to the cart or update quantity if it already exists (upsert operation).
Request Body:
{
"user_id": "uuid (required)",
"menu_item_id": "uuid (required)",
"quantity": number (default: 1)
}
Response:
{
"id": "uuid",
"user_id": "uuid",
"menu_item_id": "uuid",
"quantity": number
}
Status Codes:
- 201 — Created or Updated
- 400 — Bad Request (missing required fields)
- 500 — Server error
Notes: If quantity < 1, the item is automatically removed from the cart. Uses upsert with conflict resolution on (user_id, menu_item_id).
GET /api/cart
Get all items in a user's cart with detailed menu item information.
Query Parameters: user_id (UUID, required) — The user's unique identifier
Response:
[
{
"id": "uuid",
"quantity": number,
"menu_items": {
"id": "uuid",
"name": "string",
"price": number,
"image_url": "string",
"restaurant_id": "uuid"
}
}
]
Status Codes:
- 200 — Success
- 400 — Missing user_id parameter
- 500 — Server error
DELETE /api/cart/items/:menu_item_id
Remove a specific item from a user's cart.
Path Parameters: menu_item_id (UUID, required) — The menu item to remove
Query Parameters: user_id (UUID, required) — The user's unique identifier
Response: Empty (No Content)
Status Codes:
- 204 — Success (No Content)
- 400 — Missing user_id parameter
- 404 — Item not found in cart
- 500 — Server error