
This commit includes: - Project structure and FastAPI setup - SQLAlchemy models for users, vehicles, schedules, and tickets - Alembic migrations - User authentication and management - Vehicle and schedule management - Ticket purchase and cancellation with time restrictions - Comprehensive API documentation
Multimodal Ticketing System
A backend system built with FastAPI that allows users to purchase tickets for different transportation modes (cars, buses, trains).
Features
- User registration and authentication
- User profile management
- Vehicle management (cars, buses, trains)
- Schedule management for different vehicles
- Ticket purchasing with time restrictions
- Ticket cancellation with time restrictions
- View active tickets and ticket history
Requirements
- Python 3.8+
- SQLite database
Environment Variables
The application uses the following environment variables:
Variable | Description | Default |
---|---|---|
SECRET_KEY | JWT secret key | "09d25e094faa6ca2556c818166b7a9563b93f7099f6f0f4caa6cf63b88e8d3e7" |
ACCESS_TOKEN_EXPIRE_MINUTES | Token expiration time in minutes | 30 |
Installation
- Clone the repository:
git clone <repository-url>
cd multimodalticketingsystem
- Create a virtual environment and activate it:
python -m venv venv
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
- Install the required dependencies:
pip install -r requirements.txt
- Run the database migrations:
alembic upgrade head
- Start the application:
uvicorn main:app --reload
The API will be available at http://localhost:8000.
API Documentation
The API documentation is available at:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
API Endpoints
Authentication
POST /api/v1/auth/register
- Register a new userPOST /api/v1/auth/login
- Login and get access token
Users
GET /api/v1/users/me
- Get current user profilePUT /api/v1/users/me
- Update current user profile
Vehicles
GET /api/v1/vehicles
- List all vehiclesPOST /api/v1/vehicles
- Create a new vehicleGET /api/v1/vehicles/{vehicle_id}
- Get vehicle detailsPUT /api/v1/vehicles/{vehicle_id}
- Update a vehicleDELETE /api/v1/vehicles/{vehicle_id}
- Delete a vehicle (soft delete)
Schedules
GET /api/v1/vehicles/schedules
- List all schedulesPOST /api/v1/vehicles/schedules
- Create a new scheduleGET /api/v1/vehicles/schedules/{schedule_id}
- Get schedule detailsPUT /api/v1/vehicles/schedules/{schedule_id}
- Update a scheduleDELETE /api/v1/vehicles/schedules/{schedule_id}
- Delete a schedule (soft delete)
Tickets
POST /api/v1/tickets
- Purchase a ticketGET /api/v1/tickets
- List all tickets for current userGET /api/v1/tickets/active
- List active tickets for current userGET /api/v1/tickets/history
- List ticket history for current userGET /api/v1/tickets/{ticket_id}
- Get ticket details by IDGET /api/v1/tickets/by-ticket-number/{ticket_number}
- Get ticket details by ticket numberPUT /api/v1/tickets/{ticket_id}/cancel
- Cancel a ticket
Business Rules
- Tickets cannot be purchased less than 10 minutes before departure time
- Tickets cannot be cancelled less than 3 minutes before departure time
- Train tickets include a seat number, while car and bus tickets do not
- When a ticket is cancelled, the seat becomes available for purchase again
Database Structure
The system uses the following database models:
- Users: Store user information
- Vehicles: Store different types of vehicles (cars, buses, trains)
- Schedules: Store departure and arrival information for vehicles
- Tickets: Store ticket information linked to users and schedules
Description
Languages
Python
98.9%
Mako
1.1%