
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
123 lines
3.5 KiB
Markdown
123 lines
3.5 KiB
Markdown
# 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
|
|
|
|
1. Clone the repository:
|
|
|
|
```bash
|
|
git clone <repository-url>
|
|
cd multimodalticketingsystem
|
|
```
|
|
|
|
2. Create a virtual environment and activate it:
|
|
|
|
```bash
|
|
python -m venv venv
|
|
source venv/bin/activate # On Windows, use `venv\Scripts\activate`
|
|
```
|
|
|
|
3. Install the required dependencies:
|
|
|
|
```bash
|
|
pip install -r requirements.txt
|
|
```
|
|
|
|
4. Run the database migrations:
|
|
|
|
```bash
|
|
alembic upgrade head
|
|
```
|
|
|
|
5. Start the application:
|
|
|
|
```bash
|
|
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 user
|
|
- `POST /api/v1/auth/login` - Login and get access token
|
|
|
|
### Users
|
|
|
|
- `GET /api/v1/users/me` - Get current user profile
|
|
- `PUT /api/v1/users/me` - Update current user profile
|
|
|
|
### Vehicles
|
|
|
|
- `GET /api/v1/vehicles` - List all vehicles
|
|
- `POST /api/v1/vehicles` - Create a new vehicle
|
|
- `GET /api/v1/vehicles/{vehicle_id}` - Get vehicle details
|
|
- `PUT /api/v1/vehicles/{vehicle_id}` - Update a vehicle
|
|
- `DELETE /api/v1/vehicles/{vehicle_id}` - Delete a vehicle (soft delete)
|
|
|
|
### Schedules
|
|
|
|
- `GET /api/v1/vehicles/schedules` - List all schedules
|
|
- `POST /api/v1/vehicles/schedules` - Create a new schedule
|
|
- `GET /api/v1/vehicles/schedules/{schedule_id}` - Get schedule details
|
|
- `PUT /api/v1/vehicles/schedules/{schedule_id}` - Update a schedule
|
|
- `DELETE /api/v1/vehicles/schedules/{schedule_id}` - Delete a schedule (soft delete)
|
|
|
|
### Tickets
|
|
|
|
- `POST /api/v1/tickets` - Purchase a ticket
|
|
- `GET /api/v1/tickets` - List all tickets for current user
|
|
- `GET /api/v1/tickets/active` - List active tickets for current user
|
|
- `GET /api/v1/tickets/history` - List ticket history for current user
|
|
- `GET /api/v1/tickets/{ticket_id}` - Get ticket details by ID
|
|
- `GET /api/v1/tickets/by-ticket-number/{ticket_number}` - Get ticket details by ticket number
|
|
- `PUT /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 |