Added technician config seeder #127
This commit is contained in:
		| @@ -7,5 +7,5 @@ class DataSeederABC(ABC): | ||||
|         pass | ||||
|  | ||||
|     @abstractmethod | ||||
|     def seed(self): | ||||
|     async def seed(self): | ||||
|         pass | ||||
|   | ||||
| @@ -10,6 +10,10 @@ class TechnicianConfigRepositoryABC(ABC): | ||||
|     def __init__(self): | ||||
|         pass | ||||
|  | ||||
|     @abstractmethod | ||||
|     def does_technician_config_exists(self) -> bool: | ||||
|         pass | ||||
|  | ||||
|     @abstractmethod | ||||
|     def get_technician_config(self) -> TechnicianConfig: | ||||
|         pass | ||||
|   | ||||
| @@ -10,10 +10,12 @@ from bot_data.abc.api_key_repository_abc import ApiKeyRepositoryABC | ||||
| from bot_data.abc.auth_user_repository_abc import AuthUserRepositoryABC | ||||
| from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC | ||||
| from bot_data.abc.client_repository_abc import ClientRepositoryABC | ||||
| from bot_data.abc.data_seeder_abc import DataSeederABC | ||||
| from bot_data.abc.game_server_repository_abc import GameServerRepositoryABC | ||||
| from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC | ||||
| from bot_data.abc.level_repository_abc import LevelRepositoryABC | ||||
| from bot_data.abc.server_repository_abc import ServerRepositoryABC | ||||
| from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC | ||||
| from bot_data.abc.user_game_ident_repository_abc import UserGameIdentRepositoryABC | ||||
| from bot_data.abc.user_joined_game_server_repository_abc import UserJoinedGameServerRepositoryABC | ||||
| from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC | ||||
| @@ -36,6 +38,8 @@ from bot_data.service.known_user_repository_service import KnownUserRepositorySe | ||||
| from bot_data.service.level_repository_service import LevelRepositoryService | ||||
| from bot_data.service.seeder_service import SeederService | ||||
| from bot_data.service.server_repository_service import ServerRepositoryService | ||||
| from bot_data.service.technician_config_repository_service import TechnicianConfigRepositoryService | ||||
| from bot_data.service.technician_config_seeder import TechnicianConfigSeeder | ||||
| from bot_data.service.user_game_ident_repository_service import UserGameIdentRepositoryService | ||||
| from bot_data.service.user_joined_game_server_repository_service import UserJoinedGameServerRepositoryService | ||||
| from bot_data.service.user_joined_server_repository_service import ( | ||||
| @@ -80,5 +84,7 @@ class DataModule(ModuleABC): | ||||
|         services.add_transient(GameServerRepositoryABC, GameServerRepositoryService) | ||||
|         services.add_transient(UserGameIdentRepositoryABC, UserGameIdentRepositoryService) | ||||
|         services.add_transient(AchievementRepositoryABC, AchievementRepositoryService) | ||||
|         services.add_transient(TechnicianConfigRepositoryABC, TechnicianConfigRepositoryService) | ||||
|  | ||||
|         services.add_transient(SeederService) | ||||
|         services.add_transient(DataSeederABC, TechnicianConfigSeeder) | ||||
|   | ||||
| @@ -104,7 +104,7 @@ class TechnicianConfig(TableABC): | ||||
|                     '{self._help_command_reference_url}', | ||||
|                     {self._wait_for_restart}, | ||||
|                     {self._wait_for_shutdown}, | ||||
|                     {self._cache_max_messages}, | ||||
|                     {self._cache_max_messages} | ||||
|                 ); | ||||
|             """ | ||||
|         ) | ||||
|   | ||||
| @@ -50,7 +50,7 @@ class TechnicianIdConfig(TableABC): | ||||
|                 INSERT INTO `CFG_TechnicianIds` ( | ||||
|                     `TechnicianId` | ||||
|                 ) VALUES ( | ||||
|                     '{self._technician_id}', | ||||
|                     '{self._technician_id}' | ||||
|                 ); | ||||
|             """ | ||||
|         ) | ||||
|   | ||||
| @@ -50,7 +50,7 @@ class TechnicianPingUrlConfig(TableABC): | ||||
|                 INSERT INTO `CFG_TechnicianPingUrls` ( | ||||
|                     `URL` | ||||
|                 ) VALUES ( | ||||
|                     '{self._ping_url}', | ||||
|                     '{self._ping_url}' | ||||
|                 ); | ||||
|             """ | ||||
|         ) | ||||
|   | ||||
| @@ -48,6 +48,12 @@ class TechnicianConfigRepositoryService(TechnicianConfigRepositoryABC): | ||||
|             id=result[0], | ||||
|         ) | ||||
|  | ||||
|     def does_technician_config_exists(self) -> bool: | ||||
|         self._logger.trace(__name__, f"Send SQL command: {TechnicianConfig.get_select_all_string()}") | ||||
|         result = self._context.select(TechnicianConfig.get_select_all_string()) | ||||
|  | ||||
|         return len(result) > 0 | ||||
|  | ||||
|     def get_technician_config(self) -> TechnicianConfig: | ||||
|         self._logger.trace(__name__, f"Send SQL command: {TechnicianConfig.get_select_all_string()}") | ||||
|         result = self._context.select(TechnicianConfig.get_select_all_string())[0] | ||||
|   | ||||
							
								
								
									
										48
									
								
								kdb-bot/src/bot_data/service/technician_config_seeder.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										48
									
								
								kdb-bot/src/bot_data/service/technician_config_seeder.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,48 @@ | ||||
| from cpl_core.database.context import DatabaseContextABC | ||||
| from cpl_query.extension import List | ||||
|  | ||||
| from bot_core.logging.database_logger import DatabaseLogger | ||||
| from bot_data.abc.data_seeder_abc import DataSeederABC | ||||
| from bot_data.abc.technician_config_repository_abc import TechnicianConfigRepositoryABC | ||||
| from bot_data.model.technician_config import TechnicianConfig | ||||
| from bot_data.model.technician_id_config import TechnicianIdConfig | ||||
| from bot_data.model.technician_ping_url_config import TechnicianPingUrlConfig | ||||
|  | ||||
|  | ||||
| class TechnicianConfigSeeder(DataSeederABC): | ||||
|     def __init__( | ||||
|         self, | ||||
|         logger: DatabaseLogger, | ||||
|         technician_config: TechnicianConfigRepositoryABC, | ||||
|         db: DatabaseContextABC, | ||||
|     ): | ||||
|         DataSeederABC.__init__(self) | ||||
|  | ||||
|         self._logger = logger | ||||
|         self._technician_config = technician_config | ||||
|         self._db = db | ||||
|  | ||||
|     async def seed(self): | ||||
|         try: | ||||
|             if not self._technician_config.does_technician_config_exists(): | ||||
|                 config = TechnicianConfig( | ||||
|                     "https://git.sh-edraft.de/sh-edraft.de/kd_discord_bot/wiki/Befehle", | ||||
|                     8, | ||||
|                     8, | ||||
|                     1000000, | ||||
|                     List(int, [240160344557879316]), | ||||
|                     List(str, ["www.google.com", "www.sh-edraft.de", "www.keksdose-gaming.de"]), | ||||
|                 ) | ||||
|  | ||||
|                 self._technician_config.add_technician_config(config) | ||||
|                 for technician in config.technician_ids: | ||||
|                     self._technician_config.add_technician_id_config(TechnicianIdConfig(technician)) | ||||
|  | ||||
|                 for url in config.ping_urls: | ||||
|                     self._technician_config.add_technician_ping_url_config(TechnicianPingUrlConfig(url)) | ||||
|  | ||||
|                 self._db.save_changes() | ||||
|                 self._logger.debug(__name__, "Seeded technician config") | ||||
|  | ||||
|         except Exception as e: | ||||
|             self._logger.error(__name__, f"Seeding technician config failed", e) | ||||
		Reference in New Issue
	
	Block a user