Skip to content

API for a local theater, allowing visitors to make online reservations.

Notifications You must be signed in to change notification settings

Illya-Maznitskiy/theatre-api-service

Repository files navigation

Theatre API Service

Description

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.

Technologies Used

  • Python
  • Django ORM
  • Django
  • DRF
  • Docker

API Features

  • 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.

Setup

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

Commands to test the project:

You can run the tests and check code style using flake8 with the following commands:

python manage.py test
flake8

Configuration .env

  1. Create a .env file in the root directory of the project and add the necessary configuration by the sample.env file.
  2. Make sure to replace 'your_dummy_secret_key_here' with a real secret key. You can create it with Djecrety

Docker Configuration

Dockerfile

Configures the Django app environment, installs dependencies, sets the working directory, and manages media file permissions

docker-compose.yml

This file sets up the Docker services, including the Django application and PostgreSQL database:

Environment Variables (.env)

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

Docker Setup

To set up and run the project using Docker, follow these steps:

  1. Ensure Docker is Running:

    Make sure Docker Desktop is installed and running on your system.
    
  2. Build the Docker Images:

    docker-compose build
  3. Start the Services:

    docker-compose up
  4. Stop the Services:

    docker-compose down

Access

  • 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.

API Endpoints

User API

  • URL: /api/user/register/
  • URL: /api/user/login/
  • URL: /api/user/me/

Theatre API

  • 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/

Screenshots:

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)

User registration example:

This screenshot shows the form where new users can create an account. User Registration

User login by page:

Here’s a demonstration of the login page where users receive their tokens. User Login Page

User login by ModHeader:

Use the ModHeader extension to send the token and allow access to other pages. User Login by Header

Theatre API Overview:

If you correctly use the authentication token, you'll have access to the Theatre API. Theatre API

Database structure:

Database Structure

About

API for a local theater, allowing visitors to make online reservations.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published