The Train Station API Service is a RESTful API that manages a train transportation system. The service allows users to explore train stations, routes, journeys, and ticket bookings, providing a backend system for travelers to easily plan and book their train trips.
These instructions will help you set up the Train Station API Service for development and testing purposes.
- Clone the repository:
git clone [email protected]:OleksiukStepan/train-station-api-service.git cd train-station-api-service
- Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate venv\Scripts\activate (on Windows)
- Install the required dependencies:
pip install -r requirements.txt
- Set up environment variables:
Create a
.env
file in the root directory and add the following variables:POSTGRES_USER=station POSTGRES_PASSWORD=station POSTGRES_DB=station POSTGRES_HOST=db_station POSTGRES_PORT=5432 DJANGO_SECRET_KEY=your_secret_key
- Build and start the services:
docker-compose up --build
- The application will be accessible at
http://localhost:8000
.
To load sample data:
docker exec -it <your_container_name> sh
python manage.py loaddata data.json
To access the admin panel, create a superuser:
docker exec -it <your_container_name> sh
python manage.py createsuperuser
Use the following credentials when prompted:
- Email:
[email protected]
- Password:
test_12345
The API uses JWT for authentication. You can obtain a token by sending a POST request to:
POST /api/user/token/
You will receive access and refresh tokens to authenticate API requests.
/stations/
- Manage train stations./routes/
- Manage train routes between stations./trains/
- Manage trains and their types./crews/
- Manage crew members./journeys/
- Manage journeys (schedules)./tickets/
- Book tickets for journeys./orders/
- Manage ticket orders.
- JWT Authentication: Secure access to the API using JSON Web Tokens (JWT).
- Admin Panel: Accessible at /admin/ for managing the database.
- API Documentation: Available at /api/v1/doc/swagger/ for easy exploration of available endpoints.
- Order and Train Station Management: Manage orders and train stations through a user-friendly interface.
- Station Management: Create, read, update, and delete train stations.
- Route Management: Manage train routes between stations, including distance and validation to avoid circular routes.
- Train & Train Type Management: Define trains with their capacities and types, and manage the available trains in the system.
- Journey Management: Define journeys including route, train, crew, departure, and arrival times.
- Crew Management: Manage train crew members who are assigned to specific journeys.
- Ticket Booking System: Book tickets for journeys, including cargo and seating selection.
- Filtering Journeys: Filter journeys by source, destination, and date.
- User Authentication: Users can register, log in, and manage orders.