This API is designed for a local theater, allowing visitors to make online reservations, choose seats, and manage bookings. It includes endpoints for user registration, login, and access to theater data such as plays, performances, and genres.
- Python
- Django ORM
- Django
- DRF
- Docker
- CRUD Operations: Create, Read, Update, and Delete data.
- Authentication & Authorization: Secure endpoints with methods like Token Authentication.
- Testing: Ensure API reliability with tests for apps.
To install the project locally on your computer, execute the following commands in a terminal:
git clone https://github.com/Illya-Maznitskiy/theatre-api-service.git
cd theatre-api-service
python -m venv venv
venv\Scripts\activate (on Windows)
source venv/bin/activate (on macOS)
pip install -r requirements.txt
You can run the tests and check code style using flake8
with the following commands:
python manage.py test
flake8
- Create a .env file in the root directory of the project and add the necessary configuration by the sample.env file.
- Make sure to replace 'your_dummy_secret_key_here' with a real secret key. You can create it with Djecrety
Configures the Django app environment, installs dependencies, sets the working directory, and manages media file permissions
This file sets up the Docker services, including the Django application and PostgreSQL database:
These variables configure the PostgreSQL database connection. Create a .env
file in the root directory of the project and add the necessary database configuration. Example content:
DB_NAME=your_database_name
DB_USER=your_database_user
DB_PASSWORD=your_database_password
DB_HOST=db
DB_PORT=5432
PGDATA=/var/lib/postgresql/data
To set up and run the project using Docker, follow these steps:
- Use http://localhost:8001/ URL to visit the service when it starts.
-
Ensure Docker is Running:
Make sure Docker Desktop is installed and running on your system.
-
Build the Docker Images:
docker-compose build
-
Start the Services:
docker-compose up
-
Stop the Services:
docker-compose down
- Superusers: Can modify all data (e.g., add, update, delete entries) in the Theatre API.
- Authenticated Users: Can view data and create reservations and tickets but cannot modify existing data. To create a superuser, use the following command:
python manage.py createsuperuser
After creating the superuser, you can log in using these credentials on the /api/user/login/ page to get your authentication token. This token can be used for authorized access to the Theatre API.
- URL:
/api/user/register/
- URL:
/api/user/login/
- URL:
/api/user/me/
- URL:
/api/theatre/theatre-halls/
- URL:
/api/theatre/plays/
- URL:
/api/theatre/performances/
- URL:
/api/theatre/actors/
- URL:
/api/theatre/genres/
- URL:
/api/theatre/reservations/
- URL:
/api/theatre/tickets/
There are examples how to use the project with DRF API interface in browser with a ModHeader extension (alternatively, Postman or similar services can be used)
This screenshot shows the form where new users can create an account.
Here’s a demonstration of the login page where users receive their tokens.
Use the ModHeader extension to send the token and allow access to other pages.
If you correctly use the authentication token, you'll have access to the Theatre API.