diff --git a/sql/create_database.sql b/sql/create_database.sql index 84ee4d5..a8a5042 100644 --- a/sql/create_database.sql +++ b/sql/create_database.sql @@ -1,15 +1,15 @@ CREATE DATABASE IF NOT EXISTS `ez_lan_manager` /*!40100 DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci */; USE `ez_lan_manager`; --- MySQL dump 10.13 Distrib 5.7.24, for Linux (x86_64) +-- MySQL dump 10.13 Distrib 8.0.41, for Win64 (x86_64) -- -- Host: 127.0.0.1 Database: ez_lan_manager -- ------------------------------------------------------ --- Server version 5.5.5-10.11.8-MariaDB-0ubuntu0.24.04.1 +-- Server version 5.5.5-10.4.32-MariaDB /*!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 */; -/*!40101 SET NAMES utf8 */; +/*!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 */; @@ -23,7 +23,7 @@ USE `ez_lan_manager`; DROP TABLE IF EXISTS `catering_menu_items`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `catering_menu_items` ( `catering_menu_item_id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(45) NOT NULL, @@ -32,7 +32,7 @@ CREATE TABLE `catering_menu_items` ( `category` varchar(80) NOT NULL, `is_disabled` tinyint(4) DEFAULT 0, PRIMARY KEY (`catering_menu_item_id`) -) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB AUTO_INCREMENT=69 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -41,7 +41,7 @@ CREATE TABLE `catering_menu_items` ( DROP TABLE IF EXISTS `news`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `news` ( `news_id` int(11) NOT NULL AUTO_INCREMENT, `news_content` text DEFAULT NULL, @@ -52,7 +52,7 @@ CREATE TABLE `news` ( PRIMARY KEY (`news_id`), KEY `user_is_idx` (`news_author`), CONSTRAINT `user_is` FOREIGN KEY (`news_author`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -61,7 +61,7 @@ CREATE TABLE `news` ( DROP TABLE IF EXISTS `order_catering_menu_item`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `order_catering_menu_item` ( `order_id` int(11) NOT NULL, `catering_menu_item_id` int(11) NOT NULL, @@ -79,7 +79,7 @@ CREATE TABLE `order_catering_menu_item` ( DROP TABLE IF EXISTS `orders`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `orders` ( `order_id` int(11) NOT NULL AUTO_INCREMENT, `status` varchar(45) NOT NULL, @@ -87,7 +87,7 @@ CREATE TABLE `orders` ( `order_date` datetime NOT NULL DEFAULT current_timestamp(), `is_delivery` tinyint(4) NOT NULL DEFAULT 1, PRIMARY KEY (`order_id`) -) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB AUTO_INCREMENT=15 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -96,7 +96,7 @@ CREATE TABLE `orders` ( DROP TABLE IF EXISTS `seats`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `seats` ( `seat_id` varchar(5) NOT NULL, `is_blocked` tinyint(4) NOT NULL DEFAULT 0, @@ -113,7 +113,7 @@ CREATE TABLE `seats` ( DROP TABLE IF EXISTS `tickets`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `tickets` ( `ticket_id` int(11) NOT NULL AUTO_INCREMENT, `ticket_category` varchar(45) NOT NULL, @@ -122,7 +122,40 @@ CREATE TABLE `tickets` ( PRIMARY KEY (`ticket_id`), KEY `user_id_idx` (`user`), CONSTRAINT `user` FOREIGN KEY (`user`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `tournament_participants` +-- + +DROP TABLE IF EXISTS `tournament_participants`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `tournament_participants` ( + `tournament_id` int(11) NOT NULL, + `user_id` int(11) NOT NULL, + `registered_at_timestamp` varchar(45) NOT NULL DEFAULT 'CURRENT_TIMESTAMP', + PRIMARY KEY (`tournament_id`,`user_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `tournaments` +-- + +DROP TABLE IF EXISTS `tournaments`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!50503 SET character_set_client = utf8mb4 */; +CREATE TABLE `tournaments` ( + `tournament_id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(45) NOT NULL, + `additional_info` varchar(300) DEFAULT NULL, + `start_time` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(), + `participants_limit` int(4) DEFAULT NULL, + `created_at` timestamp NOT NULL DEFAULT current_timestamp(), + PRIMARY KEY (`tournament_id`,`start_time`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -131,7 +164,7 @@ CREATE TABLE `tickets` ( DROP TABLE IF EXISTS `transactions`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `transactions` ( `transaction_id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, @@ -143,7 +176,7 @@ CREATE TABLE `transactions` ( UNIQUE KEY `transaction_id_UNIQUE` (`transaction_id`), KEY `user_id_idx` (`user_id`), CONSTRAINT `user_id` FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`) ON DELETE NO ACTION ON UPDATE NO ACTION -) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB AUTO_INCREMENT=37 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; -- @@ -152,7 +185,7 @@ CREATE TABLE `transactions` ( DROP TABLE IF EXISTS `user_profile_picture`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `user_profile_picture` ( `user_id` int(11) NOT NULL, `picture` mediumblob DEFAULT NULL, @@ -167,7 +200,7 @@ CREATE TABLE `user_profile_picture` ( DROP TABLE IF EXISTS `users`; /*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; +/*!50503 SET character_set_client = utf8mb4 */; CREATE TABLE `users` ( `user_id` int(11) NOT NULL AUTO_INCREMENT, `user_name` varchar(50) NOT NULL, @@ -185,7 +218,7 @@ CREATE TABLE `users` ( UNIQUE KEY `user_id_UNIQUE` (`user_id`), UNIQUE KEY `user_mail_UNIQUE` (`user_mail`), UNIQUE KEY `user_name_UNIQUE` (`user_name`) -) ENGINE=InnoDB AUTO_INCREMENT=28 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; +) ENGINE=InnoDB AUTO_INCREMENT=33 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; /*!40101 SET character_set_client = @saved_cs_client */; /*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; @@ -197,4 +230,4 @@ CREATE TABLE `users` ( /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; /*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; --- Dump completed on 2024-08-25 22:37:14 +-- Dump completed on 2025-02-09 21:52:04 diff --git a/src/ez_lan_manager/__init__.py b/src/ez_lan_manager/__init__.py index 76fd5b7..60895c3 100644 --- a/src/ez_lan_manager/__init__.py +++ b/src/ez_lan_manager/__init__.py @@ -12,11 +12,13 @@ from src.ez_lan_manager.services.MailingService import MailingService from src.ez_lan_manager.services.NewsService import NewsService from src.ez_lan_manager.services.SeatingService import SeatingService from src.ez_lan_manager.services.TicketingService import TicketingService +from src.ez_lan_manager.services.TournamentService import TournamentService from src.ez_lan_manager.services.UserService import UserService from src.ez_lan_manager.types import * + # Inits services in the correct order -def init_services() -> tuple[AccountingService, CateringService, ConfigurationService, DatabaseService, MailingService, NewsService, SeatingService, TicketingService, UserService, LocalDataService]: +def init_services() -> tuple[AccountingService, CateringService, ConfigurationService, DatabaseService, MailingService, NewsService, SeatingService, TicketingService, UserService, LocalDataService, TournamentService]: logging.basicConfig(level=logging.DEBUG) configuration_service = ConfigurationService(from_root("config.toml")) db_service = DatabaseService(configuration_service.get_database_configuration()) @@ -25,8 +27,10 @@ def init_services() -> tuple[AccountingService, CateringService, ConfigurationSe news_service = NewsService(db_service) mailing_service = MailingService(configuration_service) ticketing_service = TicketingService(configuration_service.get_ticket_info(), db_service, accounting_service) - seating_service = SeatingService(configuration_service.get_seating_configuration(), configuration_service.get_lan_info(), db_service, ticketing_service) + tournament_service = TournamentService(db_service) + seating_service = SeatingService(configuration_service.get_seating_configuration(), + configuration_service.get_lan_info(), db_service, ticketing_service) catering_service = CateringService(db_service, accounting_service, user_service) local_data_service = LocalDataService() - return accounting_service, catering_service, configuration_service, db_service, mailing_service, news_service, seating_service, ticketing_service, user_service, local_data_service + return accounting_service, catering_service, configuration_service, db_service, mailing_service, news_service, seating_service, ticketing_service, user_service, local_data_service, tournament_service diff --git a/src/ez_lan_manager/helpers/create_demo_database_content.py b/src/ez_lan_manager/helpers/create_demo_database_content.py index 796d4d3..45504df 100644 --- a/src/ez_lan_manager/helpers/create_demo_database_content.py +++ b/src/ez_lan_manager/helpers/create_demo_database_content.py @@ -7,12 +7,15 @@ import sys from src.ez_lan_manager import init_services from src.ez_lan_manager.types.CateringMenuItem import CateringMenuItemCategory +from src.ez_lan_manager.types.Tournament import Tournament from src.ez_lan_manager.types.News import News DEMO_USERS = [ {"user_name": "manfred", "user_mail": "manfred@demomail.com", "password_clear_text": "manfred"}, # Gast - {"user_name": "gustav", "user_mail": "gustav@demomail.com", "password_clear_text": "gustav"}, # Gast + Ticket(NORMAL) - {"user_name": "jason", "user_mail": "juergen@demomail.com", "password_clear_text": "jason"}, # Gast + Ticket(NORMAL) + Sitzplatz + {"user_name": "gustav", "user_mail": "gustav@demomail.com", "password_clear_text": "gustav"}, + # Gast + Ticket(NORMAL) + {"user_name": "jason", "user_mail": "juergen@demomail.com", "password_clear_text": "jason"}, + # Gast + Ticket(NORMAL) + Sitzplatz {"user_name": "lisa", "user_mail": "lisa@demomail.com", "password_clear_text": "lisa"}, # Teamler {"user_name": "thomas", "user_mail": "thomas@demomail.com", "password_clear_text": "thomas"} # Teamler + Admin ] @@ -27,6 +30,7 @@ async def run() -> None: ticket_service = services[7] seating_service = services[6] news_service = services[5] + tournament_service = services[10] if input("Generate seating table? (y/N): ").lower() == "y": sys.exit("This part of the script is currently being reworked... :(") @@ -71,37 +75,52 @@ async def run() -> None: CateringMenuItemCategory.MAIN_COURSE) await catering_service.add_menu_item("Tortellini in Käsesauce mit Fleischfüllung", "", Decimal("10.50"), CateringMenuItemCategory.MAIN_COURSE) - await catering_service.add_menu_item("Tortellini in Käsesauce ohne Fleischfüllung", "Vegetarisch", Decimal("10.50"), + await catering_service.add_menu_item("Tortellini in Käsesauce ohne Fleischfüllung", "Vegetarisch", + Decimal("10.50"), CateringMenuItemCategory.MAIN_COURSE) # SNACK await catering_service.add_menu_item("Käse Schinken Wrap", "", Decimal("5.00"), CateringMenuItemCategory.SNACK) await catering_service.add_menu_item("Puten Paprika Wrap", "", Decimal("7.00"), CateringMenuItemCategory.SNACK) - await catering_service.add_menu_item("Tomate Mozzarella Wrap", "", Decimal("6.00"), CateringMenuItemCategory.SNACK) + await catering_service.add_menu_item("Tomate Mozzarella Wrap", "", Decimal("6.00"), + CateringMenuItemCategory.SNACK) await catering_service.add_menu_item("Portion Pommes", "", Decimal("4.00"), CateringMenuItemCategory.SNACK) await catering_service.add_menu_item("Rinds-Currywurst", "", Decimal("4.50"), CateringMenuItemCategory.SNACK) - await catering_service.add_menu_item("Rinds-Currywurst mit Pommes", "", Decimal("6.50"), CateringMenuItemCategory.SNACK) + await catering_service.add_menu_item("Rinds-Currywurst mit Pommes", "", Decimal("6.50"), + CateringMenuItemCategory.SNACK) await catering_service.add_menu_item("Nudelsalat", "", Decimal("4.50"), CateringMenuItemCategory.SNACK) - await catering_service.add_menu_item("Nudelsalat mit Bockwurst", "", Decimal("6.00"), CateringMenuItemCategory.SNACK) + await catering_service.add_menu_item("Nudelsalat mit Bockwurst", "", Decimal("6.00"), + CateringMenuItemCategory.SNACK) await catering_service.add_menu_item("Kartoffelsalat", "", Decimal("4.50"), CateringMenuItemCategory.SNACK) - await catering_service.add_menu_item("Kartoffelsalat mit Bockwurst", "", Decimal("6.00"), CateringMenuItemCategory.SNACK) - await catering_service.add_menu_item("Sandwichtoast - Schinken", "", Decimal("1.80"), CateringMenuItemCategory.SNACK) - await catering_service.add_menu_item("Sandwichtoast - Käse", "", Decimal("1.80"), CateringMenuItemCategory.SNACK) - await catering_service.add_menu_item("Sandwichtoast - Schinken/Käse", "", Decimal("2.10"), CateringMenuItemCategory.SNACK) - await catering_service.add_menu_item("Sandwichtoast - Salami", "", Decimal("1.80"), CateringMenuItemCategory.SNACK) - await catering_service.add_menu_item("Sandwichtoast - Salami/Käse", "", Decimal("2.10"), CateringMenuItemCategory.SNACK) - await catering_service.add_menu_item("Chips - Western Style", "", Decimal("1.30"), CateringMenuItemCategory.SNACK) + await catering_service.add_menu_item("Kartoffelsalat mit Bockwurst", "", Decimal("6.00"), + CateringMenuItemCategory.SNACK) + await catering_service.add_menu_item("Sandwichtoast - Schinken", "", Decimal("1.80"), + CateringMenuItemCategory.SNACK) + await catering_service.add_menu_item("Sandwichtoast - Käse", "", Decimal("1.80"), + CateringMenuItemCategory.SNACK) + await catering_service.add_menu_item("Sandwichtoast - Schinken/Käse", "", Decimal("2.10"), + CateringMenuItemCategory.SNACK) + await catering_service.add_menu_item("Sandwichtoast - Salami", "", Decimal("1.80"), + CateringMenuItemCategory.SNACK) + await catering_service.add_menu_item("Sandwichtoast - Salami/Käse", "", Decimal("2.10"), + CateringMenuItemCategory.SNACK) + await catering_service.add_menu_item("Chips - Western Style", "", Decimal("1.30"), + CateringMenuItemCategory.SNACK) await catering_service.add_menu_item("Nachos - Salted", "", Decimal("1.30"), CateringMenuItemCategory.SNACK) # DESSERT - await catering_service.add_menu_item("Panna Cotta mit Erdbeersauce", "", Decimal("7.00"), CateringMenuItemCategory.DESSERT) - await catering_service.add_menu_item("Panna Cotta mit Blaubeersauce", "", Decimal("7.00"), CateringMenuItemCategory.DESSERT) - await catering_service.add_menu_item("Mousse au Chocolat", "", Decimal("7.00"), CateringMenuItemCategory.DESSERT) + await catering_service.add_menu_item("Panna Cotta mit Erdbeersauce", "", Decimal("7.00"), + CateringMenuItemCategory.DESSERT) + await catering_service.add_menu_item("Panna Cotta mit Blaubeersauce", "", Decimal("7.00"), + CateringMenuItemCategory.DESSERT) + await catering_service.add_menu_item("Mousse au Chocolat", "", Decimal("7.00"), + CateringMenuItemCategory.DESSERT) # BREAKFAST await catering_service.add_menu_item("Fruit Loops", "", Decimal("1.50"), CateringMenuItemCategory.BREAKFAST) await catering_service.add_menu_item("Smacks", "", Decimal("1.50"), CateringMenuItemCategory.BREAKFAST) - await catering_service.add_menu_item("Knuspermüsli", "Schoko", Decimal("2.00"), CateringMenuItemCategory.BREAKFAST) + await catering_service.add_menu_item("Knuspermüsli", "Schoko", Decimal("2.00"), + CateringMenuItemCategory.BREAKFAST) await catering_service.add_menu_item("Cini Minis", "", Decimal("2.50"), CateringMenuItemCategory.BREAKFAST) await catering_service.add_menu_item("Brötchen - Schinken", "mit Margarine", Decimal("1.20"), CateringMenuItemCategory.BREAKFAST) @@ -133,12 +152,14 @@ async def run() -> None: CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC) await catering_service.add_menu_item("Spezi", "von Paulaner, 0,5L Flasche", Decimal("1.50"), CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC) - await catering_service.add_menu_item("Red Bull", "", Decimal("2.00"), CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC) + await catering_service.add_menu_item("Red Bull", "", Decimal("2.00"), + CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC) await catering_service.add_menu_item("Energy", "Hausmarke", Decimal("1.50"), CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC) # BEVERAGE_ALCOHOLIC - await catering_service.add_menu_item("Pils", "0,33L Flasche", Decimal("1.90"), CateringMenuItemCategory.BEVERAGE_ALCOHOLIC) + await catering_service.add_menu_item("Pils", "0,33L Flasche", Decimal("1.90"), + CateringMenuItemCategory.BEVERAGE_ALCOHOLIC) await catering_service.add_menu_item("Radler", "0,33L Flasche", Decimal("1.90"), CateringMenuItemCategory.BEVERAGE_ALCOHOLIC) await catering_service.add_menu_item("Diesel", "0,33L Flasche", Decimal("1.90"), @@ -151,17 +172,24 @@ async def run() -> None: CateringMenuItemCategory.BEVERAGE_ALCOHOLIC) # BEVERAGE_COCKTAIL - await catering_service.add_menu_item("Vodka Energy", "", Decimal("4.00"), CateringMenuItemCategory.BEVERAGE_COCKTAIL) - await catering_service.add_menu_item("Vodka O-Saft", "", Decimal("4.00"), CateringMenuItemCategory.BEVERAGE_COCKTAIL) + await catering_service.add_menu_item("Vodka Energy", "", Decimal("4.00"), + CateringMenuItemCategory.BEVERAGE_COCKTAIL) + await catering_service.add_menu_item("Vodka O-Saft", "", Decimal("4.00"), + CateringMenuItemCategory.BEVERAGE_COCKTAIL) await catering_service.add_menu_item("Whiskey Cola", "mit Bourbon", Decimal("4.00"), CateringMenuItemCategory.BEVERAGE_COCKTAIL) - await catering_service.add_menu_item("Jägermeister Energy", "", Decimal("4.00"), CateringMenuItemCategory.BEVERAGE_COCKTAIL) - await catering_service.add_menu_item("Sex on the Beach", "", Decimal("5.50"), CateringMenuItemCategory.BEVERAGE_COCKTAIL) - await catering_service.add_menu_item("Long Island Ice Tea", "", Decimal("5.50"), CateringMenuItemCategory.BEVERAGE_COCKTAIL) - await catering_service.add_menu_item("Caipirinha", "", Decimal("5.50"), CateringMenuItemCategory.BEVERAGE_COCKTAIL) + await catering_service.add_menu_item("Jägermeister Energy", "", Decimal("4.00"), + CateringMenuItemCategory.BEVERAGE_COCKTAIL) + await catering_service.add_menu_item("Sex on the Beach", "", Decimal("5.50"), + CateringMenuItemCategory.BEVERAGE_COCKTAIL) + await catering_service.add_menu_item("Long Island Ice Tea", "", Decimal("5.50"), + CateringMenuItemCategory.BEVERAGE_COCKTAIL) + await catering_service.add_menu_item("Caipirinha", "", Decimal("5.50"), + CateringMenuItemCategory.BEVERAGE_COCKTAIL) # BEVERAGE_SHOT - await catering_service.add_menu_item("Jägermeister", "", Decimal("2.00"), CateringMenuItemCategory.BEVERAGE_SHOT) + await catering_service.add_menu_item("Jägermeister", "", Decimal("2.00"), + CateringMenuItemCategory.BEVERAGE_SHOT) await catering_service.add_menu_item("Tequila", "", Decimal("2.00"), CateringMenuItemCategory.BEVERAGE_SHOT) await catering_service.add_menu_item("PfEZzi", "Getunter Pfefferminz-Schnaps", Decimal("1.99"), CateringMenuItemCategory.BEVERAGE_SHOT) @@ -194,6 +222,14 @@ async def run() -> None: news_date=date.today() )) + if not input("Generate default tournament? (Y/n): ").lower() == "n": + await tournament_service.add_tournament( + name="League of Legends 1vs1", + additional_info="Normal 1vs1, 100 cs, first blood, first tower, aram-map", + start_time=date.today(), + participants_limit=30 + ) + if __name__ == "__main__": with asyncio.Runner() as loop: diff --git a/src/ez_lan_manager/services/DatabaseService.py b/src/ez_lan_manager/services/DatabaseService.py index 7f6c532..8774c50 100644 --- a/src/ez_lan_manager/services/DatabaseService.py +++ b/src/ez_lan_manager/services/DatabaseService.py @@ -10,6 +10,7 @@ from src.ez_lan_manager.types.CateringOrder import CateringOrder from src.ez_lan_manager.types.CateringMenuItem import CateringMenuItem, CateringMenuItemCategory from src.ez_lan_manager.types.CateringOrder import CateringMenuItemsWithAmount, CateringOrderStatus from src.ez_lan_manager.types.ConfigurationTypes import DatabaseConfiguration +from src.ez_lan_manager.types.Tournament import Tournament from src.ez_lan_manager.types.News import News from src.ez_lan_manager.types.Seat import Seat from src.ez_lan_manager.types.Ticket import Ticket @@ -81,6 +82,18 @@ class DatabaseService: last_updated_at=data[11] ) + @staticmethod + def _map_db_result_to_tournament(data: tuple) -> Tournament: + return Tournament( + tournament_id=data[0], + tournament_name=data[1], + tournament_info=data[2], + participants_limit=data[3], + start_time=data[4], + created_at=data[5], + can_register=data[6] + ) + async def get_user_by_name(self, user_name: str) -> Optional[User]: async with self._connection_pool.acquire() as conn: async with conn.cursor(aiomysql.Cursor) as cursor: @@ -788,3 +801,73 @@ class DatabaseService: return await self.remove_profile_picture(user_id) except Exception as e: logger.warning(f"Error deleting user profile picture: {e}") + + async def get_all_tournaments(self): + async with self._connection_pool.acquire() as conn: + async with conn.cursor(aiomysql.Cursor) as cursor: + results = [] + try: + await cursor.execute("SELECT * FROM tournaments;") + await conn.commit() + except aiomysql.InterfaceError: + pool_init_result = await self.init_db_pool() + if not pool_init_result: + raise NoDatabaseConnectionError + return await self.get_all_users() + except Exception as e: + logger.warning(f"Error getting all tournaments: {e}") + return results + + for tournament_raw in await cursor.fetchall(): + results.append(self._map_db_result_to_tournament(tournament_raw)) + + return results + + async def get_tournament(self, tournament_id: int) -> Optional[Tournament]: + async with self._connection_pool.acquire() as conn: + async with conn.cursor(aiomysql.Cursor) as cursor: + await cursor.execute("SELECT * FROM tournaments WHERE tournament_id=%s", (tournament_id,)) + result = await cursor.fetchone() + if not result: + return + return self._map_db_result_to_tournament(result) + + async def get_all_registered_users_for_tournament(self, tournament_id: id) -> Optional[list[User]]: + async with self._connection_pool.acquire() as conn: + async with conn.cursor(aiomysql.Cursor) as cursor: + await cursor.execute("SELECT * FROM tournaments_participants WHERE tournament_id=%s", (tournament_id,)) + result = await cursor.fetchone() + result = [self.get_user_by_id(user_id[1]) for user_id in result] + if not result: + return + return result + + + async def set_tournament_info(self, tournament_id, tournament_info): + pass + + async def register_to_tournament(self, tournament_id, user_id): + pass + + async def unregister_to_tournament(self, tournament_id, user_id): + pass + + async def add_tournament(self, name, additional_info, start_time, participants_limit) -> None: + async with self._connection_pool.acquire() as conn: + async with conn.cursor(aiomysql.Cursor) as cursor: + try: + await cursor.execute( + "INSERT INTO tournaments (name, additional_info, start_time, participants_limit) " + "VALUES (%s, %s, %s, %s)", + (name, additional_info, start_time, participants_limit) + ) + await conn.commit() + except aiomysql.InterfaceError: + pool_init_result = await self.init_db_pool() + if not pool_init_result: + raise NoDatabaseConnectionError + return await self.add_tournament(name, additional_info, start_time, participants_limit) + except Exception as e: + logger.warning(f"Error adding Tournament: {e}") + return + diff --git a/src/ez_lan_manager/services/TournamentService.py b/src/ez_lan_manager/services/TournamentService.py new file mode 100644 index 0000000..80f546f --- /dev/null +++ b/src/ez_lan_manager/services/TournamentService.py @@ -0,0 +1,38 @@ +import logging +from typing import Optional + +from src.ez_lan_manager.services.DatabaseService import DatabaseService +from src.ez_lan_manager.types.Tournament import Tournament +from src.ez_lan_manager.types.User import User + +logger = logging.getLogger(__name__.split(".")[-1]) + + +class AlreadyRegisteredToTournamentError(Exception): + pass + + +class TournamentService: + def __init__(self, db_service: DatabaseService): + self._db_service = db_service + + async def add_tournament(self, name, additional_info, start_time, participants_limit) -> None: + await self._db_service.add_tournament(name, additional_info, start_time, participants_limit) + + async def get_all_tournaments(self) -> list[Tournament]: + return await self._db_service.get_all_tournaments() + + async def get_tournament(self, tournament_id: int) -> Tournament: + return await self._db_service.get_tournament() + + async def get_all_registered_users_for_tournament(self, tournament_id: int) -> list[User]: + return await self._db_service.get_all_registered_users_for_tournament(tournament_id) + + async def register_to_tournament(self, tournament_id: int, user_id: int) -> None: + await self._db_service.register_to_tournament(tournament_id, user_id) + + async def unregister_to_tournament(self, tournament_id: int, user_id: int) -> None: + await self._db_service.unregister_to_tournament(tournament_id, user_id) + + async def set_tournament_info(self, tournament_id: int, tournament_info: str) -> None: + await self._db_service.set_tournament_info(tournament_id, tournament_info) diff --git a/src/ez_lan_manager/types/Tournament.py b/src/ez_lan_manager/types/Tournament.py new file mode 100644 index 0000000..02be275 --- /dev/null +++ b/src/ez_lan_manager/types/Tournament.py @@ -0,0 +1,18 @@ +from dataclasses import dataclass +from datetime import date, datetime +from typing import Optional + + +@dataclass +class Tournament: + tournament_id: int + tournament_name: str + tournament_info: str + participants_limit: int + start_time: datetime + created_at: datetime + can_register: bool = True + + def __hash__(self) -> int: + return hash(str(self.tournament_id)) + diff --git a/testing/unittests/TournamentServiceTests.py b/testing/unittests/TournamentServiceTests.py new file mode 100644 index 0000000..c4a2155 --- /dev/null +++ b/testing/unittests/TournamentServiceTests.py @@ -0,0 +1,12 @@ +import unittest +from unittest.mock import MagicMock, AsyncMock + +from src.ez_lan_manager.services.TournamentService import TournamentService + + +class TournamentServiceTests(unittest.IsolatedAsyncioTestCase): + + def setUp(self) -> None: + self.mock_database_service = MagicMock() + self.mock_database_service.add_transaction = AsyncMock() + self.accounting_service = TournamentService(self.mock_database_service)