WIP
This commit is contained in:
parent
1679f537de
commit
d98482f540
@ -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.NewsService import NewsService
|
||||||
from src.ez_lan_manager.services.SeatingService import SeatingService
|
from src.ez_lan_manager.services.SeatingService import SeatingService
|
||||||
from src.ez_lan_manager.services.TicketingService import TicketingService
|
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.services.UserService import UserService
|
||||||
from src.ez_lan_manager.types import *
|
from src.ez_lan_manager.types import *
|
||||||
|
|
||||||
|
|
||||||
# Inits services in the correct order
|
# 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)
|
logging.basicConfig(level=logging.DEBUG)
|
||||||
configuration_service = ConfigurationService(from_root("config.toml"))
|
configuration_service = ConfigurationService(from_root("config.toml"))
|
||||||
db_service = DatabaseService(configuration_service.get_database_configuration())
|
db_service = DatabaseService(configuration_service.get_database_configuration())
|
||||||
@ -25,8 +27,10 @@ def init_services() -> tuple[AccountingService, CateringService, ConfigurationSe
|
|||||||
news_service = NewsService(db_service)
|
news_service = NewsService(db_service)
|
||||||
mailing_service = MailingService(configuration_service)
|
mailing_service = MailingService(configuration_service)
|
||||||
ticketing_service = TicketingService(configuration_service.get_ticket_info(), db_service, accounting_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)
|
catering_service = CateringService(db_service, accounting_service, user_service)
|
||||||
local_data_service = LocalDataService()
|
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
|
||||||
|
|||||||
@ -7,12 +7,15 @@ import sys
|
|||||||
|
|
||||||
from src.ez_lan_manager import init_services
|
from src.ez_lan_manager import init_services
|
||||||
from src.ez_lan_manager.types.CateringMenuItem import CateringMenuItemCategory
|
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
|
from src.ez_lan_manager.types.News import News
|
||||||
|
|
||||||
DEMO_USERS = [
|
DEMO_USERS = [
|
||||||
{"user_name": "manfred", "user_mail": "manfred@demomail.com", "password_clear_text": "manfred"}, # Gast
|
{"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": "gustav", "user_mail": "gustav@demomail.com", "password_clear_text": "gustav"},
|
||||||
{"user_name": "jason", "user_mail": "juergen@demomail.com", "password_clear_text": "jason"}, # Gast + Ticket(NORMAL) + Sitzplatz
|
# 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": "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
|
{"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]
|
ticket_service = services[7]
|
||||||
seating_service = services[6]
|
seating_service = services[6]
|
||||||
news_service = services[5]
|
news_service = services[5]
|
||||||
|
tournament_service = services[10]
|
||||||
|
|
||||||
if input("Generate seating table? (y/N): ").lower() == "y":
|
if input("Generate seating table? (y/N): ").lower() == "y":
|
||||||
sys.exit("This part of the script is currently being reworked... :(")
|
sys.exit("This part of the script is currently being reworked... :(")
|
||||||
@ -71,37 +75,52 @@ async def run() -> None:
|
|||||||
CateringMenuItemCategory.MAIN_COURSE)
|
CateringMenuItemCategory.MAIN_COURSE)
|
||||||
await catering_service.add_menu_item("Tortellini in Käsesauce mit Fleischfüllung", "", Decimal("10.50"),
|
await catering_service.add_menu_item("Tortellini in Käsesauce mit Fleischfüllung", "", Decimal("10.50"),
|
||||||
CateringMenuItemCategory.MAIN_COURSE)
|
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)
|
CateringMenuItemCategory.MAIN_COURSE)
|
||||||
|
|
||||||
# SNACK
|
# SNACK
|
||||||
await catering_service.add_menu_item("Käse Schinken Wrap", "", Decimal("5.00"), CateringMenuItemCategory.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("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("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", "", 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", "", 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", "", 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("Kartoffelsalat mit Bockwurst", "", Decimal("6.00"),
|
||||||
await catering_service.add_menu_item("Sandwichtoast - Schinken", "", Decimal("1.80"), CateringMenuItemCategory.SNACK)
|
CateringMenuItemCategory.SNACK)
|
||||||
await catering_service.add_menu_item("Sandwichtoast - Käse", "", Decimal("1.80"), CateringMenuItemCategory.SNACK)
|
await catering_service.add_menu_item("Sandwichtoast - Schinken", "", Decimal("1.80"),
|
||||||
await catering_service.add_menu_item("Sandwichtoast - Schinken/Käse", "", Decimal("2.10"), CateringMenuItemCategory.SNACK)
|
CateringMenuItemCategory.SNACK)
|
||||||
await catering_service.add_menu_item("Sandwichtoast - Salami", "", Decimal("1.80"), CateringMenuItemCategory.SNACK)
|
await catering_service.add_menu_item("Sandwichtoast - Käse", "", Decimal("1.80"),
|
||||||
await catering_service.add_menu_item("Sandwichtoast - Salami/Käse", "", Decimal("2.10"), CateringMenuItemCategory.SNACK)
|
CateringMenuItemCategory.SNACK)
|
||||||
await catering_service.add_menu_item("Chips - Western Style", "", Decimal("1.30"), 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)
|
await catering_service.add_menu_item("Nachos - Salted", "", Decimal("1.30"), CateringMenuItemCategory.SNACK)
|
||||||
|
|
||||||
# DESSERT
|
# 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 Erdbeersauce", "", Decimal("7.00"),
|
||||||
await catering_service.add_menu_item("Panna Cotta mit Blaubeersauce", "", Decimal("7.00"), CateringMenuItemCategory.DESSERT)
|
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 Blaubeersauce", "", Decimal("7.00"),
|
||||||
|
CateringMenuItemCategory.DESSERT)
|
||||||
|
await catering_service.add_menu_item("Mousse au Chocolat", "", Decimal("7.00"),
|
||||||
|
CateringMenuItemCategory.DESSERT)
|
||||||
|
|
||||||
# BREAKFAST
|
# BREAKFAST
|
||||||
await catering_service.add_menu_item("Fruit Loops", "", Decimal("1.50"), CateringMenuItemCategory.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("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("Cini Minis", "", Decimal("2.50"), CateringMenuItemCategory.BREAKFAST)
|
||||||
await catering_service.add_menu_item("Brötchen - Schinken", "mit Margarine", Decimal("1.20"),
|
await catering_service.add_menu_item("Brötchen - Schinken", "mit Margarine", Decimal("1.20"),
|
||||||
CateringMenuItemCategory.BREAKFAST)
|
CateringMenuItemCategory.BREAKFAST)
|
||||||
@ -133,12 +152,14 @@ async def run() -> None:
|
|||||||
CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
|
CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
|
||||||
await catering_service.add_menu_item("Spezi", "von Paulaner, 0,5L Flasche", Decimal("1.50"),
|
await catering_service.add_menu_item("Spezi", "von Paulaner, 0,5L Flasche", Decimal("1.50"),
|
||||||
CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
|
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"),
|
await catering_service.add_menu_item("Energy", "Hausmarke", Decimal("1.50"),
|
||||||
CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
|
CateringMenuItemCategory.BEVERAGE_NON_ALCOHOLIC)
|
||||||
|
|
||||||
# BEVERAGE_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"),
|
await catering_service.add_menu_item("Radler", "0,33L Flasche", Decimal("1.90"),
|
||||||
CateringMenuItemCategory.BEVERAGE_ALCOHOLIC)
|
CateringMenuItemCategory.BEVERAGE_ALCOHOLIC)
|
||||||
await catering_service.add_menu_item("Diesel", "0,33L Flasche", Decimal("1.90"),
|
await catering_service.add_menu_item("Diesel", "0,33L Flasche", Decimal("1.90"),
|
||||||
@ -151,17 +172,24 @@ async def run() -> None:
|
|||||||
CateringMenuItemCategory.BEVERAGE_ALCOHOLIC)
|
CateringMenuItemCategory.BEVERAGE_ALCOHOLIC)
|
||||||
|
|
||||||
# BEVERAGE_COCKTAIL
|
# BEVERAGE_COCKTAIL
|
||||||
await catering_service.add_menu_item("Vodka Energy", "", Decimal("4.00"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)
|
await catering_service.add_menu_item("Vodka Energy", "", Decimal("4.00"),
|
||||||
await catering_service.add_menu_item("Vodka O-Saft", "", Decimal("4.00"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)
|
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"),
|
await catering_service.add_menu_item("Whiskey Cola", "mit Bourbon", Decimal("4.00"),
|
||||||
CateringMenuItemCategory.BEVERAGE_COCKTAIL)
|
CateringMenuItemCategory.BEVERAGE_COCKTAIL)
|
||||||
await catering_service.add_menu_item("Jägermeister Energy", "", Decimal("4.00"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)
|
await catering_service.add_menu_item("Jägermeister Energy", "", Decimal("4.00"),
|
||||||
await catering_service.add_menu_item("Sex on the Beach", "", Decimal("5.50"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)
|
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("Sex on the Beach", "", Decimal("5.50"),
|
||||||
await catering_service.add_menu_item("Caipirinha", "", Decimal("5.50"), CateringMenuItemCategory.BEVERAGE_COCKTAIL)
|
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
|
# 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("Tequila", "", Decimal("2.00"), CateringMenuItemCategory.BEVERAGE_SHOT)
|
||||||
await catering_service.add_menu_item("PfEZzi", "Getunter Pfefferminz-Schnaps", Decimal("1.99"),
|
await catering_service.add_menu_item("PfEZzi", "Getunter Pfefferminz-Schnaps", Decimal("1.99"),
|
||||||
CateringMenuItemCategory.BEVERAGE_SHOT)
|
CateringMenuItemCategory.BEVERAGE_SHOT)
|
||||||
@ -194,6 +222,14 @@ async def run() -> None:
|
|||||||
news_date=date.today()
|
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__":
|
if __name__ == "__main__":
|
||||||
with asyncio.Runner() as loop:
|
with asyncio.Runner() as loop:
|
||||||
|
|||||||
@ -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.CateringMenuItem import CateringMenuItem, CateringMenuItemCategory
|
||||||
from src.ez_lan_manager.types.CateringOrder import CateringMenuItemsWithAmount, CateringOrderStatus
|
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.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.News import News
|
||||||
from src.ez_lan_manager.types.Seat import Seat
|
from src.ez_lan_manager.types.Seat import Seat
|
||||||
from src.ez_lan_manager.types.Ticket import Ticket
|
from src.ez_lan_manager.types.Ticket import Ticket
|
||||||
@ -81,6 +82,18 @@ class DatabaseService:
|
|||||||
last_updated_at=data[11]
|
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 def get_user_by_name(self, user_name: str) -> Optional[User]:
|
||||||
async with self._connection_pool.acquire() as conn:
|
async with self._connection_pool.acquire() as conn:
|
||||||
async with conn.cursor(aiomysql.Cursor) as cursor:
|
async with conn.cursor(aiomysql.Cursor) as cursor:
|
||||||
@ -790,13 +803,45 @@ class DatabaseService:
|
|||||||
logger.warning(f"Error deleting user profile picture: {e}")
|
logger.warning(f"Error deleting user profile picture: {e}")
|
||||||
|
|
||||||
async def get_all_tournaments(self):
|
async def get_all_tournaments(self):
|
||||||
pass
|
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
|
||||||
|
|
||||||
async def get_tournament(self):
|
for tournament_raw in await cursor.fetchall():
|
||||||
pass
|
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 get_all_registered_users_for_tournament(self):
|
|
||||||
pass
|
|
||||||
|
|
||||||
async def set_tournament_info(self, tournament_id, tournament_info):
|
async def set_tournament_info(self, tournament_id, tournament_info):
|
||||||
pass
|
pass
|
||||||
@ -806,3 +851,23 @@ class DatabaseService:
|
|||||||
|
|
||||||
async def unregister_to_tournament(self, tournament_id, user_id):
|
async def unregister_to_tournament(self, tournament_id, user_id):
|
||||||
pass
|
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
|
||||||
|
|
||||||
|
|||||||
@ -16,6 +16,9 @@ class TournamentService:
|
|||||||
def __init__(self, db_service: DatabaseService):
|
def __init__(self, db_service: DatabaseService):
|
||||||
self._db_service = db_service
|
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]:
|
async def get_all_tournaments(self) -> list[Tournament]:
|
||||||
return await self._db_service.get_all_tournaments()
|
return await self._db_service.get_all_tournaments()
|
||||||
|
|
||||||
|
|||||||
12
testing/unittests/TournamentServiceTests.py
Normal file
12
testing/unittests/TournamentServiceTests.py
Normal file
@ -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)
|
||||||
Loading…
Reference in New Issue
Block a user