add LAN Info config and TicketingService Boilerplate
This commit is contained in:
parent
364f11f633
commit
b1bd1b11b5
@ -1,3 +1,11 @@
|
|||||||
|
[lan]
|
||||||
|
name="EZ LAN"
|
||||||
|
iteration="0.5"
|
||||||
|
tickets={ "LUXUS" = 40, "NORMAL" = 10 }
|
||||||
|
prices={ "LUXUS" = 3000, "NORMAL" = 2500 } # Eurocent
|
||||||
|
date_from="2024-10-30 15:00:00"
|
||||||
|
date_till="2024-11-01 12:00:00"
|
||||||
|
|
||||||
[database]
|
[database]
|
||||||
db_user="demo_user"
|
db_user="demo_user"
|
||||||
db_password="demo_password"
|
db_password="demo_password"
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import sys
|
import sys
|
||||||
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
import logging
|
import logging
|
||||||
import tomllib
|
import tomllib
|
||||||
|
|
||||||
from src.ez_lan_manager.types.ConfigurationTypes import DatabaseConfiguration, MailingServiceConfiguration
|
from src.ez_lan_manager.types.ConfigurationTypes import DatabaseConfiguration, MailingServiceConfiguration, LanInfo, TicketInfo
|
||||||
|
|
||||||
logger = logging.getLogger(__name__.split(".")[-1])
|
logger = logging.getLogger(__name__.split(".")[-1])
|
||||||
|
|
||||||
@ -33,14 +34,33 @@ class ConfigurationService:
|
|||||||
|
|
||||||
def get_mailing_service_configuration(self) -> MailingServiceConfiguration:
|
def get_mailing_service_configuration(self) -> MailingServiceConfiguration:
|
||||||
try:
|
try:
|
||||||
database_configuration = self._config["mailing"]
|
mailing_configuration = self._config["mailing"]
|
||||||
return MailingServiceConfiguration(
|
return MailingServiceConfiguration(
|
||||||
smtp_server=database_configuration["smtp_server"],
|
smtp_server=mailing_configuration["smtp_server"],
|
||||||
smtp_port=database_configuration["smtp_port"],
|
smtp_port=mailing_configuration["smtp_port"],
|
||||||
sender=database_configuration["sender"],
|
sender=mailing_configuration["sender"],
|
||||||
username=database_configuration["username"],
|
username=mailing_configuration["username"],
|
||||||
password=database_configuration["password"]
|
password=mailing_configuration["password"]
|
||||||
)
|
)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.fatal("Error loading MailingServiceConfiguration, exiting...")
|
logger.fatal("Error loading MailingServiceConfiguration, exiting...")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
def get_lan_info(self) -> LanInfo:
|
||||||
|
try:
|
||||||
|
lan_info = self._config["lan"]
|
||||||
|
ticket_info = TicketInfo(
|
||||||
|
categories=list(lan_info["tickets"].keys()),
|
||||||
|
_prices=lan_info["prices"],
|
||||||
|
_available_tickets=lan_info["tickets"]
|
||||||
|
)
|
||||||
|
return LanInfo(
|
||||||
|
name=lan_info["name"],
|
||||||
|
iteration=lan_info["iteration"],
|
||||||
|
ticket_info=ticket_info,
|
||||||
|
date_from=datetime.strptime(lan_info["date_from"], "%Y-%m-%d %H:%M:%S"),
|
||||||
|
date_till=datetime.strptime(lan_info["date_till"], "%Y-%m-%d %H:%M:%S")
|
||||||
|
)
|
||||||
|
except KeyError:
|
||||||
|
logger.fatal("Error loading LAN Info, exiting...")
|
||||||
|
sys.exit(1)
|
||||||
|
|||||||
7
src/ez_lan_manager/services/TicketingService.py
Normal file
7
src/ez_lan_manager/services/TicketingService.py
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
import logging
|
||||||
|
|
||||||
|
logger = logging.getLogger(__name__.split(".")[-1])
|
||||||
|
|
||||||
|
class TicketingService:
|
||||||
|
def __init__(self) -> None:
|
||||||
|
pass
|
||||||
@ -1,4 +1,8 @@
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
class NoSuchCategoryError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class DatabaseConfiguration:
|
class DatabaseConfiguration:
|
||||||
@ -8,6 +12,24 @@ class DatabaseConfiguration:
|
|||||||
db_port: int
|
db_port: int
|
||||||
db_name: str
|
db_name: str
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class TicketInfo:
|
||||||
|
categories: list[str]
|
||||||
|
_prices: dict[str, int]
|
||||||
|
_available_tickets: dict[str, int]
|
||||||
|
|
||||||
|
def get_price(self, category: str) -> int:
|
||||||
|
try:
|
||||||
|
return self._prices[category]
|
||||||
|
except KeyError:
|
||||||
|
raise NoSuchCategoryError
|
||||||
|
|
||||||
|
def get_available_tickets(self, category: str) -> int:
|
||||||
|
try:
|
||||||
|
return self._available_tickets[category]
|
||||||
|
except KeyError:
|
||||||
|
raise NoSuchCategoryError
|
||||||
|
|
||||||
@dataclass(frozen=True)
|
@dataclass(frozen=True)
|
||||||
class MailingServiceConfiguration:
|
class MailingServiceConfiguration:
|
||||||
smtp_server: str
|
smtp_server: str
|
||||||
@ -15,3 +37,11 @@ class MailingServiceConfiguration:
|
|||||||
sender: str
|
sender: str
|
||||||
username: str
|
username: str
|
||||||
password: str
|
password: str
|
||||||
|
|
||||||
|
@dataclass(frozen=True)
|
||||||
|
class LanInfo:
|
||||||
|
name: str
|
||||||
|
iteration: str
|
||||||
|
ticket_info: TicketInfo
|
||||||
|
date_from: datetime
|
||||||
|
date_till: datetime
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user