diff --git a/src/__pycache__/constants.cpython-38.pyc b/src/__pycache__/constants.cpython-38.pyc index 5407becad84724af1ad69cce59b95785cada7604..5ea3abf5d9a57105ebe07c9c1a834cae2e71d7a8 100644 Binary files a/src/__pycache__/constants.cpython-38.pyc and b/src/__pycache__/constants.cpython-38.pyc differ diff --git a/src/__pycache__/dbfunc.cpython-38.pyc b/src/__pycache__/dbfunc.cpython-38.pyc index 80583cd309f5cd688e9e7ee73e1aeaff4cfd8f09..8346d03f6a931ec3d5de2fd06882ba260d0076ca 100644 Binary files a/src/__pycache__/dbfunc.cpython-38.pyc and b/src/__pycache__/dbfunc.cpython-38.pyc differ diff --git a/src/__pycache__/staffUser.cpython-38.pyc b/src/__pycache__/staffUser.cpython-38.pyc index 343e76504ab6456f938f01a09af3c61b5601119a..f2c28d2f5ea35cd2431b03f79b2148e91e4e7a19 100644 Binary files a/src/__pycache__/staffUser.cpython-38.pyc and b/src/__pycache__/staffUser.cpython-38.pyc differ diff --git a/src/dbfunc.py b/src/dbfunc.py index 11ee0580c5f2b74e371fb8ba0ed57380597f7f7b..828e58ab95364d930d8a4fdbc3fd5e90c5f26d97 100644 --- a/src/dbfunc.py +++ b/src/dbfunc.py @@ -58,7 +58,6 @@ def select_from_table_where(table:str, condition:str, selection:str): condition (str): condition string in SQL format, eg; "WHERE username = %s AND password_hash = %s" *columns: excepts all aditinal arguments and converts them into SQL query following SELECT as arguments, if none SQL statemnt uses *. Returns: - Returns: list(dict()) """ conn = get_connection() @@ -69,7 +68,7 @@ def select_from_table_where(table:str, condition:str, selection:str): #logging.debug(table, condition, selection) cursor = conn.cursor(dictionary=True) query = f"SELECT {selection} FROM {table} WHERE {condition}" - logging.debug(f"query={query}") + logging.debug(f"query='{query}'") cursor.execute(query) results = cursor.fetchall() # returns string in format str(dict(key:values)) if not results: @@ -85,7 +84,7 @@ def select_from_table_where(table:str, condition:str, selection:str): # conn.close() # Function to INSERT data into any table -def insert_into_table(table, data): +def insert_into_table(table:str, data:dict): """Inserts data into a specified table.""" conn = get_connection() if not conn: @@ -96,7 +95,7 @@ def insert_into_table(table, data): columns = ', '.join(data.keys()) values = ', '.join(['%s'] * len(data)) query = f"INSERT INTO {table} ({columns}) VALUES ({values})" - cursor.execute(query, tuple(data.values())) + cursor.execute(query, data.values()) conn.commit() logging.info("Data inserted successfully.") return True diff --git a/src/staffUser.py b/src/staffUser.py index 03edb2ab4911d76e16d62337b1395d8a1449c0a6..2d9b4e443fea076b0e136f8b08f2e004db2df2d4 100644 --- a/src/staffUser.py +++ b/src/staffUser.py @@ -77,8 +77,51 @@ class StaffUser: def createBooking(self): """ Adds booking to db and returns ticket if succsessful. """ - logging.debug("called createBooking method") - raise NotImplementedError() + # input data and validation loop + while True: + print("Please input booking info.") + + showing_id = int(input("\nShowing ID:")) + seats = input("\nSeats in format '1' or '1 2 3' (no dupes):") + if showing_id != None and seats != None: + # import showing data + showing_data = select_from_table_where(table="tblShowings", + selection="*", + condition=f"showing_id={showing_id}") + showing_data = showing_data[0] + logging.debug(type(showing_data)) + logging.debug(f"showing_data={showing_data}") + # check if showing_data was returned from db + if showing_data != None: + # validate selected seats + seats = seats.split(" ") + logging.debug(f"seats.split={seats}") + seats = [int(x) for x in seats] # use while seats are int, remove when seats are str. + logging.debug(f"seats.int={seats}") + seating_cap = select_from_table_where(table="tblScreens", + selection="seating_capacity", + condition=f"screen_id={showing_data['screen_id']}") + seating_cap = seating_cap[0]['seating_capacity'] + logging.debug(f"seating_cap={seating_cap}") + # check if seat selection in range + if max(seats) <= int(seating_cap) and min(seats) > 0: + # showing_id and seats exist, and seat selection is in range now save to tblBookings + price = showing_data['price'] * len(seats) + insert_data=dict(user_id=self.user_id, showing_id=showing_data['showing_id'], seat_numbers=seats, total_price=price, booking_date=showing_data['show_time']) + logging.debug(f"insert_data={insert_data}") + insert_into_table(table="tblBookings", + data=insert_data) + return + + print("Invalid seating selection.") + + else: + print("Invalid showing_id.") + + else: + print("Missing input please try again.") + + def veiwBookings(self) -> dict: """ Gets bookings from db