diff --git a/Horizon_cinema Database.sql b/Horizon_cinema Database.sql deleted file mode 100644 index c8832d0ecc84476b207af987954f0b9ba7a8c084..0000000000000000000000000000000000000000 --- 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 0000000000000000000000000000000000000000..c47db224f5cdb5a8b9a9ba00e4d7f0dec697dcab --- /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 fe78d91be143525b538954149c84a3af1a23e465..e09e231d9bdc5a9282d6e6d2b648c0b5be189f5a 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 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 6efa786e9700f2c34f8bc2840767346b39bb5f85..80583cd309f5cd688e9e7ee73e1aeaff4cfd8f09 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 51bb93f589a7b6e3ab6c71f84265f5941a3ec3db..343e76504ab6456f938f01a09af3c61b5601119a 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 88634867c9ea67daf3d596a92d9481549322fa21..11ee0580c5f2b74e371fb8ba0ed57380597f7f7b 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 e5b2aceb2a354437bfc4b44e08af4a0de529c604..03edb2ab4911d76e16d62337b1395d8a1449c0a6 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.")