From f4a687b696167389dd97c464937a0a422b0ca725 Mon Sep 17 00:00:00 2001 From: n9-baker <nathan2.baker@live.uwe.ac.uk> Date: Mon, 17 Mar 2025 18:03:54 +0000 Subject: [PATCH] added veiw functionality refactored lots of var names to match db --- Horizon_cinema Database.sql | 232 ----------------------- database.sql | 220 +++++++++++++++++++++ main.py | 30 ++- src/__pycache__/constants.cpython-38.pyc | Bin 507 -> 507 bytes src/__pycache__/dbfunc.cpython-38.pyc | Bin 5005 -> 4544 bytes src/__pycache__/staffUser.cpython-38.pyc | Bin 4056 -> 4136 bytes src/dbfunc.py | 35 +--- src/staffUser.py | 91 ++++----- 8 files changed, 294 insertions(+), 314 deletions(-) delete mode 100644 Horizon_cinema Database.sql create mode 100644 database.sql diff --git a/Horizon_cinema Database.sql b/Horizon_cinema Database.sql deleted file mode 100644 index c8832d0..0000000 --- a/Horizon_cinema Database.sql +++ /dev/null @@ -1,232 +0,0 @@ --- MySQL dump 10.13 Distrib 8.0.19, for Win64 (x86_64) --- --- Host: localhost Database: horizon_cinema --- ------------------------------------------------------ --- Server version 8.0.19 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!50503 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `bookings` --- - -DROP TABLE IF EXISTS `bookings`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `bookings` ( - `booking_id` int NOT NULL AUTO_INCREMENT, - `user_id` int DEFAULT NULL, - `showing_id` int DEFAULT NULL, - `seat_number` varchar(10) NOT NULL, - `total_price` decimal(6,2) NOT NULL, - `booking_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - PRIMARY KEY (`booking_id`), - KEY `user_id` (`user_id`), - KEY `showing_id` (`showing_id`), - CONSTRAINT `bookings_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE CASCADE, - CONSTRAINT `bookings_ibfk_2` FOREIGN KEY (`showing_id`) REFERENCES `showings` (`showing_id`) ON DELETE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `bookings` --- - -LOCK TABLES `bookings` WRITE; -/*!40000 ALTER TABLE `bookings` DISABLE KEYS */; -/*!40000 ALTER TABLE `bookings` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `cancellations` --- - -DROP TABLE IF EXISTS `cancellations`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `cancellations` ( - `cancellation_id` int NOT NULL AUTO_INCREMENT, - `booking_id` int DEFAULT NULL, - `cancelled_by` int DEFAULT NULL, - `cancellation_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, - `refund_amount` decimal(6,2) DEFAULT NULL, - PRIMARY KEY (`cancellation_id`), - KEY `booking_id` (`booking_id`), - KEY `cancelled_by` (`cancelled_by`), - CONSTRAINT `cancellations_ibfk_1` FOREIGN KEY (`booking_id`) REFERENCES `bookings` (`booking_id`) ON DELETE CASCADE, - CONSTRAINT `cancellations_ibfk_2` FOREIGN KEY (`cancelled_by`) REFERENCES `users` (`user_id`) ON DELETE SET NULL -) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `cancellations` --- - -LOCK TABLES `cancellations` WRITE; -/*!40000 ALTER TABLE `cancellations` DISABLE KEYS */; -/*!40000 ALTER TABLE `cancellations` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `cinemas` --- - -DROP TABLE IF EXISTS `cinemas`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `cinemas` ( - `cinema_id` int NOT NULL AUTO_INCREMENT, - `city` varchar(50) NOT NULL, - `location` varchar(255) NOT NULL, - PRIMARY KEY (`cinema_id`) -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `cinemas` --- - -LOCK TABLES `cinemas` WRITE; -/*!40000 ALTER TABLE `cinemas` DISABLE KEYS */; -INSERT INTO `cinemas` VALUES (1,'Birmingham','Downtown Birmingham'),(2,'London','West End'),(3,'Birmingham','Downtown Birmingham'),(4,'London','West End'),(5,'Birmingham','Downtown Birmingham'),(6,'London','West End'),(7,'Birmingham','Downtown Birmingham'),(8,'London','West End'),(9,'Birmingham','Downtown Birmingham'),(10,'London','West End'); -/*!40000 ALTER TABLE `cinemas` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `films` --- - -DROP TABLE IF EXISTS `films`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `films` ( - `film_id` int NOT NULL AUTO_INCREMENT, - `title` varchar(100) NOT NULL, - `genre` varchar(50) DEFAULT NULL, - `age_rating` varchar(10) DEFAULT NULL, - `duration` int NOT NULL, - `description` text, - PRIMARY KEY (`film_id`) -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `films` --- - -LOCK TABLES `films` WRITE; -/*!40000 ALTER TABLE `films` DISABLE KEYS */; -INSERT INTO `films` VALUES (1,'Interstellar','Sci-Fi','PG-13',169,'A team of explorers travel through a wormhole in space.'),(2,'Inception','Action','PG-13',148,'A thief who enters people’s dreams.'),(3,'Interstellar','Sci-Fi','PG-13',169,'A team of explorers travel through a wormhole in space.'),(4,'Inception','Action','PG-13',148,'A thief who enters people’s dreams.'),(5,'Interstellar','Sci-Fi','PG-13',169,'A team of explorers travel through a wormhole in space.'),(6,'Inception','Action','PG-13',148,'A thief who enters people’s dreams.'),(7,'Interstellar','Sci-Fi','PG-13',169,'A team of explorers travel through a wormhole in space.'),(8,'Inception','Action','PG-13',148,'A thief who enters people’s dreams.'),(9,'Interstellar','Sci-Fi','PG-13',169,'A team of explorers travel through a wormhole in space.'),(10,'Inception','Action','PG-13',148,'A thief who enters people’s dreams.'); -/*!40000 ALTER TABLE `films` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `screens` --- - -DROP TABLE IF EXISTS `screens`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `screens` ( - `screen_id` int NOT NULL AUTO_INCREMENT, - `cinema_id` int DEFAULT NULL, - `screen_number` int NOT NULL, - `seating_capacity` int DEFAULT NULL, - PRIMARY KEY (`screen_id`), - KEY `cinema_id` (`cinema_id`), - CONSTRAINT `screens_ibfk_1` FOREIGN KEY (`cinema_id`) REFERENCES `cinemas` (`cinema_id`) ON DELETE CASCADE, - CONSTRAINT `screens_chk_1` CHECK ((`seating_capacity` between 50 and 120)) -) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `screens` --- - -LOCK TABLES `screens` WRITE; -/*!40000 ALTER TABLE `screens` DISABLE KEYS */; -INSERT INTO `screens` VALUES (1,1,1,100),(2,1,2,120),(3,2,1,80),(4,1,1,100),(5,1,2,120),(6,2,1,80),(7,1,1,100),(8,1,2,120),(9,2,1,80),(10,1,1,100),(11,1,2,120),(12,2,1,80),(13,1,1,100),(14,1,2,120),(15,2,1,80); -/*!40000 ALTER TABLE `screens` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `showings` --- - -DROP TABLE IF EXISTS `showings`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `showings` ( - `showing_id` int NOT NULL AUTO_INCREMENT, - `film_id` int DEFAULT NULL, - `screen_id` int DEFAULT NULL, - `show_time` datetime NOT NULL, - `price` decimal(5,2) NOT NULL, - PRIMARY KEY (`showing_id`), - KEY `film_id` (`film_id`), - KEY `screen_id` (`screen_id`), - CONSTRAINT `showings_ibfk_1` FOREIGN KEY (`film_id`) REFERENCES `films` (`film_id`) ON DELETE CASCADE, - CONSTRAINT `showings_ibfk_2` FOREIGN KEY (`screen_id`) REFERENCES `screens` (`screen_id`) ON DELETE CASCADE -) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `showings` --- - -LOCK TABLES `showings` WRITE; -/*!40000 ALTER TABLE `showings` DISABLE KEYS */; -INSERT INTO `showings` VALUES (1,1,1,'2025-05-10 18:00:00',10.00),(2,2,2,'2025-05-10 21:00:00',12.00),(3,1,1,'2025-05-10 18:00:00',10.00),(4,2,2,'2025-05-10 21:00:00',12.00),(5,1,1,'2025-05-10 18:00:00',10.00),(6,2,2,'2025-05-10 21:00:00',12.00),(7,1,1,'2025-05-10 18:00:00',10.00),(8,2,2,'2025-05-10 21:00:00',12.00),(9,1,1,'2025-05-10 18:00:00',10.00),(10,2,2,'2025-05-10 21:00:00',12.00); -/*!40000 ALTER TABLE `showings` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Table structure for table `users` --- - -DROP TABLE IF EXISTS `users`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!50503 SET character_set_client = utf8mb4 */; -CREATE TABLE `users` ( - `user_id` int NOT NULL AUTO_INCREMENT, - `username` varchar(50) NOT NULL, - `password_hash` varchar(255) NOT NULL, - `role` enum('Admin','Manager','Staff') NOT NULL, - PRIMARY KEY (`user_id`), - UNIQUE KEY `username` (`username`) -) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; -/*!40101 SET character_set_client = @saved_cs_client */; - --- --- Dumping data for table `users` --- - -LOCK TABLES `users` WRITE; -/*!40000 ALTER TABLE `users` DISABLE KEYS */; -INSERT INTO `users` VALUES (10,'admin','password','Admin'),(15,'manager','password','Manager'),(21,'staff','password','Staff'); -/*!40000 ALTER TABLE `users` ENABLE KEYS */; -UNLOCK TABLES; - --- --- Dumping events for database 'horizon_cinema' --- -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2025-02-19 11:08:45 diff --git a/database.sql b/database.sql new file mode 100644 index 0000000..c47db22 --- /dev/null +++ b/database.sql @@ -0,0 +1,220 @@ +-- MySQL dump 10.13 Distrib 8.0.41, for Linux (x86_64) +-- +-- Host: 127.0.0.1 Database: nathan2baker_prj +-- ------------------------------------------------------ +-- Server version 8.0.41-0ubuntu0.20.04.1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!50503 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `tblBookings` +-- + +DROP TABLE IF EXISTS `tblBookings`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `tblBookings` ( + `booking_id` int NOT NULL AUTO_INCREMENT, + `user_id` int DEFAULT NULL, + `showing_id` int DEFAULT NULL, + `seat_numbers` varchar(255) NOT NULL, + `total_price` decimal(6,2) NOT NULL, + `booking_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (`booking_id`), + KEY `user_id` (`user_id`), + KEY `showing_id` (`showing_id`), + CONSTRAINT `tblBookings_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `tblUsers` (`user_id`) ON DELETE CASCADE, + CONSTRAINT `tblBookings_ibfk_2` FOREIGN KEY (`showing_id`) REFERENCES `tblShowings` (`showing_id`) ON DELETE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `tblBookings` +-- + +/*!40000 ALTER TABLE `tblBookings` DISABLE KEYS */; +INSERT INTO `tblBookings` VALUES (8,10,2,'2b,3b,4c',30.00,'2025-03-17 17:56:27'),(9,15,2,'15a,16a',20.00,'2025-03-17 17:56:58'); +/*!40000 ALTER TABLE `tblBookings` ENABLE KEYS */; + +-- +-- Table structure for table `tblCancellations` +-- + +DROP TABLE IF EXISTS `tblCancellations`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `tblCancellations` ( + `cancellation_id` int NOT NULL AUTO_INCREMENT, + `booking_id` int DEFAULT NULL, + `cancelled_by` int DEFAULT NULL, + `cancellation_date` timestamp NULL DEFAULT CURRENT_TIMESTAMP, + `refund_amount` decimal(6,2) DEFAULT NULL, + PRIMARY KEY (`cancellation_id`), + KEY `booking_id` (`booking_id`), + KEY `cancelled_by` (`cancelled_by`), + CONSTRAINT `tblCancellations_ibfk_1` FOREIGN KEY (`booking_id`) REFERENCES `tblBookings` (`booking_id`) ON DELETE CASCADE, + CONSTRAINT `tblCancellations_ibfk_2` FOREIGN KEY (`cancelled_by`) REFERENCES `tblUsers` (`user_id`) ON DELETE SET NULL +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `tblCancellations` +-- + +/*!40000 ALTER TABLE `tblCancellations` DISABLE KEYS */; +/*!40000 ALTER TABLE `tblCancellations` ENABLE KEYS */; + +-- +-- Table structure for table `tblCinemas` +-- + +DROP TABLE IF EXISTS `tblCinemas`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `tblCinemas` ( + `cinema_id` int NOT NULL AUTO_INCREMENT, + `city` varchar(50) NOT NULL, + `location` varchar(255) NOT NULL, + PRIMARY KEY (`cinema_id`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `tblCinemas` +-- + +/*!40000 ALTER TABLE `tblCinemas` DISABLE KEYS */; +INSERT INTO `tblCinemas` VALUES (1,'Birmingham','Downtown Birmingham'),(2,'London','West End'),(3,'Birmingham','Downtown Birmingham'),(4,'London','West End'),(5,'Birmingham','Downtown Birmingham'),(6,'London','West End'),(7,'Birmingham','Downtown Birmingham'),(8,'London','West End'),(9,'Birmingham','Downtown Birmingham'),(10,'London','West End'); +/*!40000 ALTER TABLE `tblCinemas` ENABLE KEYS */; + +-- +-- Table structure for table `tblFilms` +-- + +DROP TABLE IF EXISTS `tblFilms`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `tblFilms` ( + `film_id` int NOT NULL AUTO_INCREMENT, + `title` varchar(100) NOT NULL, + `genre` varchar(50) DEFAULT NULL, + `age_rating` varchar(10) DEFAULT NULL, + `duration` int NOT NULL, + `description` text, + PRIMARY KEY (`film_id`) +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `tblFilms` +-- + +/*!40000 ALTER TABLE `tblFilms` DISABLE KEYS */; +INSERT INTO `tblFilms` VALUES (1,'Interstellar','Sci-Fi','PG-13',169,'A team of explorers travel through a wormhole in space.'),(2,'Inception','Action','PG-13',148,'A thief who enters people’s dreams.'),(3,'Interstellar','Sci-Fi','PG-13',169,'A team of explorers travel through a wormhole in space.'),(4,'Inception','Action','PG-13',148,'A thief who enters people’s dreams.'),(5,'Interstellar','Sci-Fi','PG-13',169,'A team of explorers travel through a wormhole in space.'),(6,'Inception','Action','PG-13',148,'A thief who enters people’s dreams.'),(7,'Interstellar','Sci-Fi','PG-13',169,'A team of explorers travel through a wormhole in space.'),(8,'Inception','Action','PG-13',148,'A thief who enters people’s dreams.'),(9,'Interstellar','Sci-Fi','PG-13',169,'A team of explorers travel through a wormhole in space.'),(10,'Inception','Action','PG-13',148,'A thief who enters people’s dreams.'); +/*!40000 ALTER TABLE `tblFilms` ENABLE KEYS */; + +-- +-- Table structure for table `tblScreens` +-- + +DROP TABLE IF EXISTS `tblScreens`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `tblScreens` ( + `screen_id` int NOT NULL AUTO_INCREMENT, + `cinema_id` int DEFAULT NULL, + `screen_number` int NOT NULL, + `seating_capacity` int DEFAULT NULL, + PRIMARY KEY (`screen_id`), + KEY `cinema_id` (`cinema_id`), + CONSTRAINT `tblScreens_ibfk_1` FOREIGN KEY (`cinema_id`) REFERENCES `tblCinemas` (`cinema_id`) ON DELETE CASCADE, + CONSTRAINT `tblScreens_chk_1` CHECK ((`seating_capacity` between 50 and 120)) +) ENGINE=InnoDB AUTO_INCREMENT=16 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `tblScreens` +-- + +/*!40000 ALTER TABLE `tblScreens` DISABLE KEYS */; +INSERT INTO `tblScreens` VALUES (1,1,1,100),(2,1,2,120),(3,2,1,80),(4,1,1,100),(5,1,2,120),(6,2,1,80),(7,1,1,100),(8,1,2,120),(9,2,1,80),(10,1,1,100),(11,1,2,120),(12,2,1,80),(13,1,1,100),(14,1,2,120),(15,2,1,80); +/*!40000 ALTER TABLE `tblScreens` ENABLE KEYS */; + +-- +-- Table structure for table `tblShowings` +-- + +DROP TABLE IF EXISTS `tblShowings`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `tblShowings` ( + `showing_id` int NOT NULL AUTO_INCREMENT, + `film_id` int DEFAULT NULL, + `screen_id` int DEFAULT NULL, + `show_time` datetime NOT NULL, + `price` decimal(5,2) NOT NULL, + PRIMARY KEY (`showing_id`), + KEY `film_id` (`film_id`), + KEY `screen_id` (`screen_id`), + CONSTRAINT `tblShowings_ibfk_1` FOREIGN KEY (`film_id`) REFERENCES `tblFilms` (`film_id`) ON DELETE CASCADE, + CONSTRAINT `tblShowings_ibfk_2` FOREIGN KEY (`screen_id`) REFERENCES `tblScreens` (`screen_id`) ON DELETE CASCADE +) ENGINE=InnoDB AUTO_INCREMENT=11 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `tblShowings` +-- + +/*!40000 ALTER TABLE `tblShowings` DISABLE KEYS */; +INSERT INTO `tblShowings` VALUES (1,1,1,'2025-05-10 18:00:00',10.00),(2,2,2,'2025-05-10 21:00:00',12.00),(3,1,1,'2025-05-10 18:00:00',10.00),(4,2,2,'2025-05-10 21:00:00',12.00),(5,1,1,'2025-05-10 18:00:00',10.00),(6,2,2,'2025-05-10 21:00:00',12.00),(7,1,1,'2025-05-10 18:00:00',10.00),(8,2,2,'2025-05-10 21:00:00',12.00),(9,1,1,'2025-05-10 18:00:00',10.00),(10,2,2,'2025-05-10 21:00:00',12.00); +/*!40000 ALTER TABLE `tblShowings` ENABLE KEYS */; + +-- +-- Table structure for table `tblUsers` +-- + +DROP TABLE IF EXISTS `tblUsers`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `tblUsers` ( + `user_id` int NOT NULL AUTO_INCREMENT, + `username` varchar(50) NOT NULL, + `password_hash` varchar(255) NOT NULL, + `role` enum('Admin','Manager','Staff') NOT NULL, + `cinemas` json DEFAULT NULL, + PRIMARY KEY (`user_id`), + UNIQUE KEY `username` (`username`) +) ENGINE=InnoDB AUTO_INCREMENT=22 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `tblUsers` +-- + +/*!40000 ALTER TABLE `tblUsers` DISABLE KEYS */; +INSERT INTO `tblUsers` VALUES (10,'admin','password','Admin',NULL),(15,'manager','password','Manager',NULL),(21,'staff','password','Staff',NULL); +/*!40000 ALTER TABLE `tblUsers` ENABLE KEYS */; + +-- +-- Dumping routines for database 'nathan2baker_prj' +-- +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2025-03-17 18:02:53 diff --git a/main.py b/main.py index fe78d91..e09e231 100644 --- a/main.py +++ b/main.py @@ -41,8 +41,10 @@ def loginAttempt(username: str, password: str): # using dbfuncs to do this: cursor.execute("SELECT username, password_hash, role FROM users WHERE username = %s AND password_hash = %s", (username, password)) user_data = select_from_table_where("tblUsers", f"username = '{username}' AND password_hash = '{password}'", "user_id, username, password_hash, role, cinemas") + user_data = user_data[0] logging.debug(user_data) + if user_data: logging.info(f"User '{user_data['username']}' logged in successfully.") @@ -80,7 +82,10 @@ def staffUser_options_cli(user:StaffUser) -> None: # switch case: if selection == "1": logging.debug("selection 1, loading View bookings") - user.veiwBookings() + data = user.veiwBookings() + print(data) + print(type(data)) + logging.debug(f"\n# {data}") elif selection == "2": logging.debug("selection 2, loading Create booking") user.createBooking() @@ -217,7 +222,8 @@ def managerUser_options_cli(user:ManagerUser) -> None: # uhhhh this is messy af, would love to make this smaller at some other time. XD if selection == "1": logging.debug("selection 1, loading View bookings") - user.veiwBookings() + data = pd.DataFrame(user.veiwBookings()) # data format is pd.dataframe(list(dict())) + print(data) elif selection == "2": logging.debug("selection 2, loading Create booking") user.createBooking() @@ -233,7 +239,8 @@ def managerUser_options_cli(user:ManagerUser) -> None: user.createTicket() elif selection == "6": logging.debug("selection 6, Veiw Showings") - user.viewShowings() + data = pd.DataFrame(user.veiwShowings()) + print(data) elif selection == "7": logging.debug("selection 7, Add showing") user.createShowing() @@ -246,7 +253,8 @@ def managerUser_options_cli(user:ManagerUser) -> None: user.updateShowing() elif selection == "10": logging.debug("selection 10, Veiw films") - user.veiwFilms() + data = pd.DataFrame(user.veiwFilms()) + print(data) elif selection == "11": logging.debug("selection 11, Add film") user.createFilm() @@ -259,7 +267,8 @@ def managerUser_options_cli(user:ManagerUser) -> None: user.updateFilm() elif selection == "14": logging.debug("selection 14, Veiw users") - user.veiwUsers() + data = pd.DataFrame(user.veiwUsers()) + print(data) elif selection == "15": logging.debug("selection 15, Add user") user.createUser() @@ -272,7 +281,8 @@ def managerUser_options_cli(user:ManagerUser) -> None: user.updateUser() elif selection == "18": logging.debug("selection 18, Veiw Cinemas") - user.veiwsCinemas() + data = pd.DataFrame(user.veiwsCinemas()) + print(data) elif selection == "19": logging.debug("selection 19, Add Cinema") user.createCinema() @@ -328,7 +338,7 @@ def main_cli() -> None: # exit() print("To login please enter your credentials.\n") while True: - username = encrypt(sanitize(input("Username: "))) + username = encrypt(sanitize(input("username: "))) password = encrypt(sanitize(input("Password: "))) user = loginAttempt(username=username, password=password) logging.debug(f"user object={user}") @@ -338,9 +348,9 @@ def main_cli() -> None: else: break - logging.info(f"Successfuly loged in as {user.userName}, loading menu... ") - logging.debug(f"id={user.userID}, name={user.userName}, pass={user.userPass}, role={user.role}, cin={user.cinemas}") - logging.debug(f"{type(user.userID)}, {type(user.userName)}, {type(user.userPass)}, {type(user.role)}, {type(user.cinemas)}") + logging.info(f"Successfuly loged in as {user.username}, loading menu... ") + logging.debug(f"id={user.user_id}, name={user.username}, pass={user.password_hash}, role={user.role}, cin={user.cinemas}") + logging.debug(f"{type(user.user_id)}, {type(user.username)}, {type(user.password_hash)}, {type(user.role)}, {type(user.cinemas)}") # based on the different user permision levels, load different menus. diff --git a/src/__pycache__/constants.cpython-38.pyc b/src/__pycache__/constants.cpython-38.pyc index fdf0909528cee8886cd22a1b6aeb1ed58ae1c478..5407becad84724af1ad69cce59b95785cada7604 100644 GIT binary patch delta 19 acmey({F|98l$V!_fq{X+*?uF}M@9fLMg*?_ delta 19 acmey({F|98l$V!_fq{V`hi@a-M@9fLM+Bz; diff --git a/src/__pycache__/dbfunc.cpython-38.pyc b/src/__pycache__/dbfunc.cpython-38.pyc index 6efa786e9700f2c34f8bc2840767346b39bb5f85..80583cd309f5cd688e9e7ee73e1aeaff4cfd8f09 100644 GIT binary patch delta 335 zcmeBGKcLJP%FD~ez`($8BlbqRm+(YB8OE-O+Fh)S!3>(h8&5H^FuG4Z!=j+hrJ$go z5R_U{T9j981?GSRax#lcG*U8?OEfe!!Ge?DusmX9oqV1(NMs)a149WzGea$N4RbMH zIzuo+Ro-M%wgipY40D+lGBPsMu!S=OGq5m}uw}7lab$B9?O<f6WoKllk}6?Zz?s4| z`6!z@Gk4;;&F|Uz8D;U>J-La)WAb^9b!w&z3=G9eApdZ)F|shSFflRlFp4n>Fmf?+ zFtRXmF|siVFtTl4%xS~K7_s>Q_YX$K{LMFck1#U!Y@Ww2%*fa>d6R%Hlcw<G!$J*= uqLU{I2y1ZI<mRW8=A_y&f(#d9U|`^21VJ7~31$H%4lxc<A!QD64p9IlnoYX^ delta 808 zcmX@0+^fzP%FD~ez`($eZgeBPNpvEg4CAbc+Fhc;DIzTlQNk&rDPk=QQ6edf!3>(> z8+S3XFe*%DWEYuyfrV!>GwUNprpeD(gG7!oFff!bG&9sP*Dx3Jr85LGRFzHkVM{Pb z;gV#S%`lf~AtNJ04I79T&JfJN!cfAN#h%5H%~f=Ok)f8Ik)cYeglPe13isqIZ0gKB ziBmWKW9w&RNy$tunY@a_gSCi}fq`N2CysS$MhpxL#Y!LtbFne9FtRW)G4U{pF$yqp zF>)}nFmf@nF^Vv9Z9c|n!^9Y}nVIJYBV+dFKfFg689O!~<QHaSY?ypiK({^_WC9E` zGcYiKurtVP3z%0JY8Z-4Y8bK@Qy5d2dKqgOYZw<Wr7(ki!nlBWAww-w4Z{MKg$#@g zHB7+_AWv(u_=OZnFfcGw2?x9SxH^X@Xeqb_`THt_7N-^!uVgI}XJB9`l4W41XDE^f zF%>|B3<Cp$CUcQ6h%L*&z!1e+3Q}Gq3K9SlVhjunx46?%OOi9<!E#eUE)@W|pAi%a zJYe60{9k0nz`%gpb1qQN)z^Z2XG6euj8Na9`7(tim_d`ZN|#GPK|#R{<S2#2oE(MR z{Ibl{VuiG#{9J{Sj8uh`#FE6M#Nt#vusUeCh(N-n9u_dZU`>8Smgr%?1~Cpj5O^Sg z0Fj&z3I!ohD6k-h0tX`tQ;{{uK+z&TP{^@l73b$g@#j_+7v|_C=jY|6PL>hOU;_nJ nk@e&TK{Yuk1_lNWMiAs-lwcNM;t=By5>nz2=Md!(<=_GUREVVb diff --git a/src/__pycache__/staffUser.cpython-38.pyc b/src/__pycache__/staffUser.cpython-38.pyc index 51bb93f589a7b6e3ab6c71f84265f5941a3ec3db..343e76504ab6456f938f01a09af3c61b5601119a 100644 GIT binary patch delta 1840 zcmca1ze0g8l$V!_fq{WxZPJbOMxlv(GBF7Z3=Am@DU3M`Q4pFjiV@6biegS-N@31n z$z_dVWn@TUN@2-i3jxurIqbO{Q5=j6?hGkxDeNr_DeTQmQJkq<DID2MMKP(I%?wf8 zsXVFN6YD$}XG}bvqs^DXK8G<yBt^7^C5k^qI+Zz<Ih8e4AVq8rONw}kL<?(_V2Wgl zR0~6t(Bu@xN=5e4;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Jz87#KJh#ke`R`1tsE_}Do(IaoQ^_}KW^I9S1|K!sCoVrE`^ye2m!%w#~O pY~<Gyumfc|R#4V9EV2X%e&kmc0_AW4Mjl2EMjjTvQVu3IMgU21y5#@> diff --git a/src/dbfunc.py b/src/dbfunc.py index 8863486..11ee058 100644 --- a/src/dbfunc.py +++ b/src/dbfunc.py @@ -30,7 +30,10 @@ def get_connection(): # Function to SELECT data from any table def select_from_table(table, *args): - """Fetches data from a given table.""" + """Fetches data from a given table. + Returns: + list(dict()) + """ conn = get_connection() try: @@ -55,7 +58,8 @@ 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: - dict + Returns: + list(dict()) """ conn = get_connection() if not conn: @@ -71,8 +75,8 @@ def select_from_table_where(table:str, condition:str, selection:str): if not results: logging.debug("SQL return empty.") return None - logging.debug(f"SQL results={results[0]}") - return results[0] + logging.debug(f"SQL results={results}") + return results except mysql.connector.Error as err: logging.error(f"Error fetching data with condition: {err}") return None @@ -146,27 +150,4 @@ def update_table(table, data, condition): cursor.close() conn.close() -def fetch_users(): - conn = get_connection() - if conn: - cursor = conn.cursor(dictionary=True) - cursor.execute("SELECT * FROM Users") - users = cursor.fetchall() - conn.close() - return users - return [] -def fetch_movies(): - """ - Fetch all movies from the database. - """ - conn = get_connection() - if conn: - cursor = conn.cursor(dictionary=True) - cursor.execute("SELECT * FROM Movies") # Change 'Movies' to your actual table name - movies = cursor.fetchall() - cursor.close() - conn.close() - return movies - else: - return [] diff --git a/src/staffUser.py b/src/staffUser.py index e5b2ace..03edb2a 100644 --- a/src/staffUser.py +++ b/src/staffUser.py @@ -1,4 +1,5 @@ import logging, json +import datetime as dt from .constants import DBNAME from .dbfunc import * from .cinemaObj import Cinema @@ -8,9 +9,9 @@ from .cinemaObj import Cinema class StaffUser: def __init__(self, id:int, name:str, passw:str, role:str, cinemas:list): # staff id number assigned by manager during onboarding. - self.userID:int = id - self.userName:str = name - self.userPass:str = passw + self.user_id:int = id + self.username:str = name + self.password_hash:str = passw # staff software level. self.role:str = role # list of branches active at. @@ -24,30 +25,29 @@ class StaffUser: # function not working, causes massive recursion? #def __repr__(self): - #"""this function returns this object in a string readable format, eg; print(staffUser) returns 'StaffUser user object(userID=1, userName='user', userPass='password'... ' """ - # return f"{self.__class__.__name__} user object(userID={self.userID}, userName={self.userName}, userPass={self.userPass}, permissionLevel={self.role})" + #"""this function returns this object in a string readable format, eg; print(staffUser) returns 'StaffUser user object(user_id=1, username='user', password_hash='password'... ' """ + # return f"{self.__class__.__name__} user object(user_id={self.user_id}, username={self.username}, password_hash={self.password_hash}, permissionLevel={self.role})" - def login(self, userName, userPassword) -> None: + def login(self, username, password_hash) -> None: """ Get values for self from db """ - logging.debug("called login func") - jsonData = select_from_tbl_where("tblUsers", f"userName='{userName}' AND userPass='{userPassword}'") - dictData = json.loads(jsonData) - logging.debug(f"loaded data: {jsonData}") + logging.debug("called login method") + data = select_from_tbl_where("tblUsers", f"username='{username}' AND password_hash='{password_hash}'") + logging.debug(f"loaded data: {data}") # this will loop with i as any key from dictData and self.dict that matches, i hope lol. - for i in dictData.keys(), self.__dict__.keys(): + for i in data[0].keys(), self.__dict__.keys(): self.i = dictData[i] # replace cinema_ids in self.cinemas with Cinema objects for i in self.cinemas: self.cinemas[i] = Cinema(id=i) def _save_self_to_db(self) -> None: - """ Save all self attributes to db. internal function. + """ Save all self attributes to db. internal method. """ selfDir = self.__dict__ # pull out class variables and values as dict - selfDir['user_id'] = selfDir.pop('userID') - selfDir['password_hash'] = selfDir.pop('userPass') - logging.debug(f"called _save_self_to_db func with data:{selfDir}") + selfDir['user_id'] = selfDir.pop('user_id') + selfDir['password_hash'] = selfDir.pop('password_hash') + logging.debug(f"called _save_self_tomethod with data:{selfDir}") try: update_table(table="tblUsers", condition=f"user_id = '{selfDir['user_id']}'", data=selfDir.pop('user_id')) except Exception as e: @@ -56,14 +56,14 @@ class StaffUser: def logout(self) -> None: """ Save user to db. external function. """ - logging.debug("called logout func") - logging.info(f"user {self.userName} logging out.") + logging.debug("called logmethod") + logging.info(f"user {self.username} logging out.") #self._save_self_to_db() def return_film_listings(self): """ gets film listings from cinema object """ - logging.debug("called returnFilmListings func") + logging.debug("called returnFilmListimethod") listings = [] for cinema in self.cinemas: listings.append(cinema.get_showings()) @@ -77,42 +77,43 @@ class StaffUser: def createBooking(self): """ Adds booking to db and returns ticket if succsessful. """ - logging.debug("called createBooking func") + logging.debug("called createBooking method") raise NotImplementedError() - def veiwBookings(self) -> list: + def veiwBookings(self) -> dict: + """ Gets bookings from db """ - """ - logging.debug("called veiwBookings func") - raise NotImplementedError() + logging.debug("called StaffUser.veiwBookings method") + data = select_from_table(table="tblBookings") # need to change this to use a mySQL veiw + logging.debug(data) + return data - def updateBooking(self) -> None: - """ + def updateBooking(self, booking_id, user_id:int=None, showing_id:int=None, seat_numbers:list=None, total_price:float=None, booking_date=None): + """ updates existing booking from db """ - logging.debug("called manageBooking func") - raise NotImplementedError() + logging.debug("called manageBooking method") + set_data = {} + if user_id is not None: + set_data.update({'user_id':user_id}) + if showing_id is not None: + set_data.update({'showing_id':showing_id}) + if seat_numbers is not None: + set_data.update({'seat_numbers':seat_numbers}) + if total_price is not None: + set_data.update({'total_price':total_price}) + if booking_date is not None: + set_data.update({'booking_date':booking_date}) + + update_table("tblBookings", data=set_data, condition=f"booking_id = {booking_id}") def veiwShowings(self): + """ Gets showings from db """ - """ - raise NotImplementedError() + logging.debug("called StaffUser.veiwShowings method") + data = select_from_table(table="tblShowings") # need to change this to use a mySQL veiw + logging.debug(data) + return data - def cli_view_film_listings(self) -> None: # cant work out how to implement this function in main.py... would like to remove. - """ - """ - logging.debug("called cli_viewFilmListing func") - for i in self.returnFilmListings(): - # will need formating, from json? - print(f"listing:{i}") - - selection = int(input("Options: 1-exit, 2-move to create booking, 3-logout\n: ")) - - if selection == 2: - self.createBooking() - elif selection == 3: - self.logout() - else: - print("input invalid, try again with valid option.") -- GitLab