API service for managing train trips, creating orders, and buying tickets. Written in Python using Django REST Framework.
- JWT Authentication (Register, Login, Refresh)
- Admin Panel to manage trains, stations, and trips.
- Documentation via Swagger UI.
- Validation: Cannot buy a ticket for an occupied seat.
- Filtering: Find trips by city and date.
- Dockerized: Run efficiently with Docker & PostgreSQL.
- Python 3.11+
- Django 5 & DRF
- PostgreSQL
- Docker & Docker Compose
-
Clone the repository:
git clone [https://github.com/nastyagst/train-station-api.git](https://github.com/nastyagst/train-station-api.git) cd train-station-api -
Create .env file: Copy the sample config:
cp .env.sample .env
Note: Inside .env, define variables like POSTGRES_DB, POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_HOST=db, POSTGRES_PORT=5432.
-
Build and run with Docker:
docker-compose up --build
-
Access the API:
- API Root: http://127.0.0.1:8002/api/station/
- Swagger Docs: http://127.0.0.1:8002/api/doc/swagger/
To run tests inside the Docker container:
docker-compose exec app python manage.py test
- Register a new user (/api/user/register/).
- Obtain Token (/api/user/token/).
- Create Stations (e.g., Kyiv, Lviv).
- Create Route (Kyiv -> Lviv).
- Create Train (Define capacity and type).
- Create Journey (Assign a Train to a Route at a specific time).
- Buy Tickets (Create an Order with selected seats).