Skip to content

Provide the implementation of a backend service in C++ which is used for booking online movie tickets

License

Notifications You must be signed in to change notification settings

SashaZezulinsky/movie_booking_service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Movie Booking Service

The Movie Booking Service is a REST API designed to handle movie booking operations for theaters. It allows users to add movies, associate them with theaters, view available seats, and book seats for a movie in a specific theater. The project is built using C++ with the Crow framework and utilizes Conan for dependency management. The API exposes multiple endpoints to manage movie-related operations, such as adding movies, listing available theaters, checking seat availability, and booking seats.

Key Features

  • Add movies to the system.
  • Associate theaters with movies.
  • Check seat availability for specific theaters.
  • Book seats for movies.
  • Expose a RESTful API for each operation.

Requirements

  • Conan for dependency management.
  • C++17 for building the project.
  • Crow (a modern C++ web framework).
  • Make for building the project.
  • Docker (Optional) for running service in a container.

Project Structure

  • src/ - Contains the main source code for the application.
  • scripts/ - Contains bash scripts for testing the endpoints by simulating various operations such as adding movies, booking seats, etc.
  • conanfile.txt - Conan file for managing external dependencies like Crow.

Install Dependencies

To install the project dependencies using Conan, follow these steps:

Install Conan

python3 -m pip install --upgrade pip
python3 -m pip install conan
conan profile detect

Building the Project

Command to build a service

 make build

Running the Service

Run binary

./bin/movie_booking_service

Run Makefile

make run

The service will start and listen on port 8080.

Running with Docker

Build the image

docker build -t movie_booking_service:latest .

Run the container

docker run -p 8080:8080 movie_booking_service

Run the container from the Docker Hub

docker run -p 8080:8080 zezulinsky/movie_booking_service:latest

Testing with Bash Scripts

The scripts/ folder contains multiple bash scripts to test the API endpoints.

You can use these to interact with the movie booking service.

  • add_movies.sh: Adds movies to the service.
  • get_movies.sh: Lists added movies.
  • add_theaters.sh: Add theaters for movies.
  • get_theaters.sh: Lists theaters showing a movie.
  • show_available_seats.sh: Shows available seats for a movie in a theater.
  • book_seats.sh: Books seats for a movie in a theater.

How can I test a service?

Add Movies

Use the add_movies.sh script to add movies to the service.

This script sends a POST request to the /add_movie endpoint to add multiple movies.

Example

 ./scripts/add_movies.sh

Output

Adding movie: The Godfather
Response: {"movieName":"The Godfather"}
------------------------------------
Adding movie: Schindler's List
Response: {"movieName":"Schindler's List"}
------------------------------------
Adding movie: Pulp Fiction
Response: {"movieName":"Pulp Fiction"}
------------------------------------
Adding movie: Fight Club
Response: {"movieName":"Fight Club"}
------------------------------------

Get Movies

Use the get_movies.sh script to list all the added movies.

This script sends a GET request to the /movies endpoint.

Example

 ./scripts/get_movies.sh

Output

[
  {
    "movieName": "The Godfather"
  },
  {
    "movieName": "Schindler's List"
  },
  {
    "movieName": "Pulp Fiction"
  },
  {
    "movieName": "Fight Club"
  }
]

Add Theaters to Movies

Use the add_theaters.sh script to associate theaters with movies.

This script sends a POST request to the /add_theaters_to_movie endpoint for each movie.

Example

 ./scripts/add_theaters.sh

Output

Adding theaters to movie: Fight Club
Response: Theaters added for a movie
Adding theaters to movie: The Godfather
Response: Theaters added for a movie
Adding theaters to movie: Schindler List
Response: Theaters added for a movie
Adding theaters to movie: Pulp Fiction
Response: Theaters added for a movie

Get Theaters for a Movie

Use the get_theaters.sh script to list all theaters playing a particular movie.

This script sends a POST request to the /movies/theaters endpoint.

Example

 ./scripts/get_theaters.sh

Output

Schindler's List
[]
The Godfather
[
  {
    "theaterName": "The Vito Corleone Theater"
  },
  {
    "theaterName": "The Family Cinema"
  }
]
Pulp Fiction
[
  {
    "theaterName": "The Reservoir Dogs Theater"
  },
  {
    "theaterName": "The Fiction Lounge"
  }
]
Fight Club
[
  {
    "theaterName": "The Underground Theater"
  },
  {
    "theaterName": "The Rebel Cinema"
  }
]

Show Available Seats

To check available seats in a theater for a specific movie, use the show_available_seats.sh script.

It interacts with the /movies/seats endpoint

Example

 ./scripts/show_available_seats.sh "Fight Club" "The Rebel Cinema"

Output

Response for 'Fight Club' in 'The Rebel Cinema'
[
  "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10",
  "a11", "a12", "a13", "a14", "a15", "a16", "a17", "a18", "a19", "a20"
]

Book Seats

To book one or more seats for a movie in a particular theater, use the book_seats.sh script.

The script sends a POST request to the /movies/book_seats endpoint.

Example

./scripts/book_seats.sh "Fight Club" "The Rebel Cinema" "a17" "a18"

Output

Response for 'Fight Club' in 'The Rebel Cinema': Seats booked successfully.

Check Available Seats Again

After booking, you can run the show_available_seats.sh script again to confirm the booking:

Example

./scripts/show_available_seats.sh "Fight Club" "The Rebel Cinema"

Output

Response for 'Fight Club' in 'The Rebel Cinema'
[
  "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "a10",
  "a11", "a12", "a13", "a14", "a15", "a16", "a19", "a20"
]

Available Endpoints

1. Add a Movie

  • Endpoint: POST /add_movie
  • Request:
{ "movieName": "The Matrix" }
  • Response:
{ "movieName": "The Matrix" }

2. List All Movies

  • Endpoint: GET /movies
  • Response:
    [
      { "movieName": "The Matrix" },
      { "movieName": "Inception" }
    ]

3. Add Theaters to a Movie

  • Endpoint: POST /add_theaters_to_movie
  • Request body:
    {
      "movieName": "The Matrix",
      "theaters": ["Theater 1", "Theater 2", "Theater 3"]
    }
  • Response:
    {
      "movieName": "The Matrix",
      "theaters": [
        {
          "theaterName": "Theater 1"
        },
        {
          "theaterName": "Theater 2"
        },
        {
          "theaterName": "Theater 3"
        }
      ]
    }

4. List Theaters Showing a Movie

  • Endpoint: POST /movies/theaters
  • Request body:
{
  "movieName": "The Matrix"
}
  • Response:
[
  {
    "theaterName": "Theater A"
  },
  {
    "theaterName": "Theater B"
  }
]

5. View Available Seats

  • Endpoint: POST /movies/seats
  • Request body:
{ "movieName": "The Matrix", "theaterName": "IMAX" }
  • Response:
[
  "a1", "a2", "a3", "a20"
]

6. Book Seats for a Movie

  • Endpoint: POST /movies/book_seats
  • Request body:
{ "movieName": "The Matrix", "theaterName": "IMAX", "seats": ["a10", "a11"] }
  • Response:
{ "message": "Seats booked successfully." }

7. View Available Seats After Booking

  • Endpoint: POST /movies/seats
  • Request body:
{ "movieName": "The Matrix", "theaterName": "IMAX" }
  • Response:
[
  "a1", "a2", "a3", "a9", "a12", "a13", "a20"
]

About

Provide the implementation of a backend service in C++ which is used for booking online movie tickets

Resources

License

Stars

Watchers

Forks

Packages

No packages published