A python and PostgreSQL-based movie theater reservation system that handles movie listings, seat management, bookings, and payments. https://roadmap.sh/projects/movie-reservation-system
DATABASE_URL = 'dbname=moviesreservation user=beamer password=allhailkingjulien host=localhost'
start_connection()
: Establishes database connection using configured credentialscreate_table(table_name, columns, conn)
: Creates database tables with specified schema
Creates a new customer account with hashed password.
# Example usage
create_customer('johndoe', 'password123', 'john@example.com', conn)
Verifies user credentials and returns user data if valid.
# Example usage
user_data = verify_user('johndoe', 'hashed_password', conn)
Retrieves user details by username.
# Example usage
user = get_user_by_username('johndoe', conn)
Fetches trending movies from IMDB API.
- Returns: List of movies with title, duration, poster URL, and release year
Updates database with fetched movies.
Automatically generates show times for all movies:
- Operational hours: 8:00 AM - 11:58 PM
- Includes 30-minute breaks between shows
- Handles duration parsing and scheduling
Initializes theater seats with:
- Front seats (20): $40-50
- Middle seats (60): $25-40
- Back seats (20): $12-25
- Various amenities (headphones, cupholders, corner positions)
Resets all seats to available status.
Resets a specific seat to available status.
Checks seat availability:
- Returns 0: Available
- Returns 1: Booked
- Returns "seat does not exist": Invalid seat
Checks for booking time conflicts.
Creates a new booking:
- Validates seat availability
- Checks time conflicts
- Creates booking record
- Returns confirmation or error message
Retrieves all bookings for a specific customer.
Cancels a specific booking.
Retrieves price for specific seat.
Processes payment and confirms booking.
POST /api/users/register
{
"username": string,
"password": string,
"email": string
}
POST /api/users/login
{
"username": string,
"password": string
}
GET /api/users/{username}
GET /api/movies
Returns list of available movies
POST /api/movies/update
Updates movie database with latest trending movies
GET /api/movies/showtimes
Returns all movie showtimes
GET /api/seats
Returns all seats with status
GET /api/seats/{seat_id}
Returns specific seat details
POST /api/seats/reset
Resets all seats to available
POST /api/seats/reset/{seat_id}
Resets specific seat to available
GET /api/seats/check/{seat_id}
Checks seat availability
POST /api/bookings
{
"seat_id": integer,
"movie_id": integer,
"customer_id": integer
}
GET /api/bookings/customer/{customer_id}
Returns all bookings for customer
DELETE /api/bookings/{booking_id}
Cancels specific booking
GET /api/payments/price/{seat_id}
Returns price for specific seat
POST /api/payments
{
"customer_id": integer,
"amount": float,
"booking_id": integer
}
CREATE TABLE movie_table (
movie_id SERIAL PRIMARY KEY,
movie_name VARCHAR(256),
movie_duration VARCHAR(50) NOT NULL,
start_time TIME,
end_time TIME,
available_seats INTEGER[],
start_times TIMESTAMP[],
movie_poster VARCHAR(256),
release_year INTEGER
);
CREATE TABLE seats_table (
seat_id SERIAL PRIMARY KEY,
seat_category VARCHAR(20) CHECK(seat_category IN ('Front','Middle','Backseat')),
seat_price DECIMAL(10,2),
seat_book_time TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
seat_free_time TIMESTAMP,
seat_is_in_use BOOLEAN DEFAULT TRUE,
seat_is_corner BOOLEAN DEFAULT FALSE,
seat_has_headphones BOOLEAN DEFAULT FALSE,
seat_has_cupholder BOOLEAN DEFAULT FALSE,
movie_id INTEGER REFERENCES movie_table(movie_id) ON DELETE CASCADE
);
CREATE TABLE bookings_table (
booking_id SERIAL PRIMARY KEY,
seat_id INTEGER REFERENCES seats_table(seat_id) ON DELETE CASCADE,
movie_id INTEGER REFERENCES movie_table(movie_id) ON DELETE CASCADE,
booking_start_time TIMESTAMP,
booking_end_time TIMESTAMP,
is_confirmed BOOLEAN DEFAULT TRUE,
customer_id INTEGER REFERENCES registred_customers_table(customer_id) ON DELETE CASCADE
);
CREATE TABLE registred_customers_table (
customer_id SERIAL PRIMARY KEY,
customer_username VARCHAR(255),
customer_password VARCHAR(255),
customer_email VARCHAR(255)
);
- All functions include appropriate error handling
- Database connection errors are caught and logged
- Invalid seat/movie IDs return appropriate error messages
- Booking conflicts are properly handled and reported
- psycopg2: PostgreSQL adapter for Python
- werkzeug.security: Password hashing
- requests: API calls for movie data
- datetime: Time and date handling
- Set up PostgreSQL database
- Configure DATABASE_URL
- Run table creation scripts
- Initialize seats with
populate_seats()
- Fetch initial movies with
update_movies_to_be_shown()
- Set up show times with
set_movie_showTimes()