Microservice responsible for event management, including creation, updates, interests, and event-related operations.
The Event Service handles all event-related functionality including:
- Event creation and management
- Event search and filtering
- Interest-based event discovery
- Event interest management
- Async event processing with task tracking
API Gateway β Composite Service β Event Service β Event Database (VM MySQL)
- Port: 8002
- Database: MySQL (on VM or local)
- Authentication: Trusts
x-firebase-uidheader from API Gateway - Pub/Sub: Publishes
event-createdmessages
- Python 3.9+
- MySQL 8.0+
- Firebase service account key
- Google Cloud Pub/Sub (for production)
-
Install dependencies
pip install -r requirements.txt
-
Set up database
mysql -u root -p event_db < ../DB-Service/initEvent.sql -
Configure environment variables Create a
.envfile:DB_HOST=127.0.0.1 DB_USER=root DB_PASS=your_password DB_NAME=event_db GCP_PROJECT_ID=your-project-id PUBSUB_EVENT_CREATED_TOPIC=event-created FIREBASE_SERVICE_ACCOUNT_PATH=./serviceAccountKey.json
-
Add Firebase service account key
- Download from Firebase Console
- Place as
serviceAccountKey.jsonin service directory
-
Run the service
uvicorn main:app --host 0.0.0.0 --port 8002
| Variable | Description | Default | Required |
|---|---|---|---|
DB_HOST |
Database host address | 127.0.0.1 |
Yes |
DB_USER |
Database username | root |
Yes |
DB_PASS |
Database password | - | Yes |
DB_NAME |
Database name | event_db |
Yes |
GCP_PROJECT_ID |
GCP project ID for Pub/Sub | - | Yes (for Pub/Sub) |
PUBSUB_EVENT_CREATED_TOPIC |
Pub/Sub topic name | event-created |
No |
FIREBASE_SERVICE_ACCOUNT_PATH |
Path to Firebase service account JSON | ./serviceAccountKey.json |
No |
Get all events with pagination and filtering
Query Parameters:
skip: Number of events to skip (default: 0)limit: Number of events to return (default: 10, max: 100)interest_id: Filter by interest IDcreated_by: Filter by creator user IDsearch: Search in title and descriptionstart_time_from: Filter events starting after this time (ISO 8601)start_time_to: Filter events starting before this time (ISO 8601)
Headers:
x-firebase-uid: Firebase user ID (injected by API Gateway)
Response:
{
"items": [
{
"event_id": 1,
"title": "Tech Meetup",
"description": "Monthly tech meetup",
"location": "San Francisco",
"start_time": "2024-01-15T18:00:00",
"end_time": "2024-01-15T20:00:00",
"created_by": 1,
"interests": [
{"interest_id": 1, "interest_name": "Technology"}
],
"_links": {
"self": {"href": "/events/1"},
"collection": {"href": "/events"}
}
}
],
"total": 50,
"skip": 0,
"limit": 10
}ETag Support: Returns ETag header for caching
Get event by ID
Response:
{
"event_id": 1,
"title": "Tech Meetup",
"description": "Monthly tech meetup",
"location": "San Francisco",
"start_time": "2024-01-15T18:00:00",
"end_time": "2024-01-15T20:00:00",
"created_by": 1,
"interests": [...],
"_links": {...}
}Create a new event
Request Body:
{
"title": "Tech Meetup",
"description": "Monthly tech meetup",
"location": "San Francisco",
"start_time": "2024-01-15T18:00:00",
"end_time": "2024-01-15T20:00:00",
"interest_ids": [1, 2, 3]
}Response:
201 Createdwith event data202 Acceptedif async processing (with task_id)
Pub/Sub: Publishes event-created message to Pub/Sub topic
Update an event (full update)
Request Body:
{
"title": "Updated Tech Meetup",
"description": "Updated description",
"location": "New Location",
"start_time": "2024-01-15T19:00:00",
"end_time": "2024-01-15T21:00:00"
}ETag Support: Requires If-Match header for optimistic locking
Partially update an event
Request Body:
{
"title": "Updated Title",
"location": "New Location"
}ETag Support: Requires If-Match header
Delete an event
ETag Support: Requires If-Match header
Get interests for an event
Add interests to an event
Request Body:
{
"interest_ids": [1, 2, 3]
}Remove interest from an event
Get task status for async event creation
Response:
{
"task_id": "uuid-here",
"status": "completed",
"result": {
"event_id": 1,
"title": "Tech Meetup"
},
"created_at": "2024-01-01T00:00:00",
"completed_at": "2024-01-01T00:00:05"
}This service does not perform Firebase authentication directly. It trusts the x-firebase-uid header injected by the API Gateway middleware.
event_id(INT, PRIMARY KEY, AUTO_INCREMENT)title(VARCHAR)description(TEXT)location(VARCHAR)start_time(DATETIME)end_time(DATETIME)created_by(INT, FOREIGN KEY to Users)created_at(TIMESTAMP)updated_at(TIMESTAMP)
event_id(INT, FOREIGN KEY)interest_id(INT, FOREIGN KEY)
task_id(VARCHAR, PRIMARY KEY)status(ENUM: pending, processing, completed, failed)result(JSON)created_at(TIMESTAMP)completed_at(TIMESTAMP)
When an event is created, the service publishes a message to the event-created Pub/Sub topic:
{
"event_id": 1,
"title": "Tech Meetup",
"created_by": 1,
"created_at": "2024-01-01T00:00:00"
}The Composite Service subscribes to this topic and sends email notifications.
docker build -t event-service .docker run -p 8002:8002 \
-e DB_HOST=your_db_host \
-e DB_USER=your_db_user \
-e DB_PASS=your_db_password \
-e DB_NAME=event_db \
-e GCP_PROJECT_ID=your-project-id \
event-serviceThe service is deployed to Cloud Run with:
- VPC Connector for database access (connects to VM MySQL)
- Private IP connection to Event Database VM
- Pub/Sub publisher permissions
- Environment variables configured via deployment script
See ../GCP_DEPLOYMENT_GUIDE.md for details.
curl http://localhost:8002/curl -H "x-firebase-uid: your-firebase-uid" \
http://localhost:8002/eventscurl -X POST \
-H "x-firebase-uid: your-firebase-uid" \
-H "Content-Type: application/json" \
-d '{
"title": "Test Event",
"description": "Test Description",
"location": "Test Location",
"start_time": "2024-12-31T18:00:00",
"end_time": "2024-12-31T20:00:00",
"interest_ids": [1]
}' \
http://localhost:8002/eventsInteractive API documentation available at:
- Swagger UI:
http://localhost:8002/docs - ReDoc:
http://localhost:8002/redoc - OpenAPI JSON:
http://localhost:8002/openapi.json
The service returns standard HTTP status codes:
200 OK: Successful request201 Created: Event created202 Accepted: Event creation accepted (async processing)400 Bad Request: Invalid request data401 Unauthorized: Missing or invalidx-firebase-uidheader404 Not Found: Event not found409 Conflict: ETag mismatch (optimistic locking)412 Precondition Failed: ETag required but not provided500 Internal Server Error: Server error
- HATEOAS: All responses include
_linksfor navigation - ETag Support: Optimistic locking for updates
- Pagination: Skip/limit for large result sets
- Filtering: By interest, creator, time range, search
- Async Processing: Background task processing for event creation
- Pub/Sub Integration: Event-driven notifications
- The service uses MySQL connector with dictionary cursor for JSON-like responses
- ETag is generated from event data for optimistic locking
- Async event creation stores tasks in database for status tracking
- All datetime fields use ISO 8601 format
When adding new endpoints:
- Add route to
routers/events.py - Use
get_firebase_uid_from_header()helper for authentication - Add proper error handling and ETag support
- Update this README with endpoint documentation