diff --git a/bot/src/bot_data/service/achievements_repository_service.py b/bot/src/bot_data/service/achievements_repository_service.py index d8923db5..48af2c81 100644 --- a/bot/src/bot_data/service/achievements_repository_service.py +++ b/bot/src/bot_data/service/achievements_repository_service.py @@ -48,66 +48,60 @@ class AchievementRepositoryService(AchievementRepositoryABC): ) def get_achievements(self) -> List[Achievement]: - achievements = List(Achievement) self._logger.trace(__name__, f"Send SQL command: {Achievement.get_select_all_string()}") - results = self._context.select(Achievement.get_select_all_string()) - for result in results: - self._logger.trace(__name__, f"Get user with id {result[0]}") - achievements.append(self._from_result(result)) - return achievements + return List( + Achievement, + [self._from_result(result) for result in self._context.select(Achievement.get_select_all_string())], + ) def get_achievement_by_id(self, id: int) -> Achievement: self._logger.trace(__name__, f"Send SQL command: {Achievement.get_select_by_id_string(id)}") - result = self._context.select(Achievement.get_select_by_id_string(id))[0] - - return self._from_result(result) + return self._from_result(self._context.select(Achievement.get_select_by_id_string(id))[0]) def get_achievements_by_server_id(self, server_id: int) -> List[Achievement]: - achievements = List(Achievement) self._logger.trace( __name__, f"Send SQL command: {Achievement.get_select_by_server_id_string(server_id)}", ) - results = self._context.select(Achievement.get_select_by_server_id_string(server_id)) - for result in results: - self._logger.trace(__name__, f"Get user with id {result[0]}") - achievements.append(self._from_result(result)) - return achievements + return List( + Achievement, + [ + self._from_result(result) + for result in self._context.select(Achievement.get_select_by_server_id_string(server_id)) + ], + ) def get_achievements_by_user_id(self, user_id: int) -> List[Achievement]: - achievements = List(Achievement) - achievements_joins = List(UserGotAchievement) self._logger.trace( __name__, f"Send SQL command: {UserGotAchievement.get_select_by_user_id_string(user_id)}", ) - results = self._context.select(UserGotAchievement.get_select_by_user_id_string(user_id)) - for result in results: - self._logger.trace(__name__, f"Got UserGotAchievement with id {result[0]}") - achievements_joins.append(self._join_from_result(result)) - for achievements_join in achievements_joins: - results = self._context.select(Achievement.get_select_by_id_string(achievements_join.achievement.id)) - for result in results: - self._logger.trace(__name__, f"Got Achievement with id {result[0]}") - achievements.append(self._from_result(result)) - - return achievements + return List( + UserGotAchievement, + [ + self._join_from_result(result).achievement + for result in self._context.select(UserGotAchievement.get_select_by_user_id_string(user_id)) + ], + ) def get_user_got_achievements_by_achievement_id(self, achievement_id: int) -> List[Achievement]: - achievements_joins = List(UserGotAchievement) self._logger.trace( __name__, f"Send SQL command: {UserGotAchievement.get_select_by_achievement_id_string(achievement_id)}", ) - results = self._context.select(UserGotAchievement.get_select_by_achievement_id_string(achievement_id)) - for result in results: - self._logger.trace(__name__, f"Got UserGotAchievement with id {result[0]}") - achievements_joins.append(self._join_from_result(result)) - return achievements_joins + return List( + UserGotAchievement, + [ + self._join_from_result(result) + for result in self._context.select( + UserGotAchievement.get_select_by_achievement_id_string(achievement_id) + ) + ], + ) def add_achievement(self, achievement: Achievement): self._logger.trace(__name__, f"Send SQL command: {achievement.insert_string}") diff --git a/bot/src/bot_data/service/api_key_repository_service.py b/bot/src/bot_data/service/api_key_repository_service.py index d4f57dfc..13904738 100644 --- a/bot/src/bot_data/service/api_key_repository_service.py +++ b/bot/src/bot_data/service/api_key_repository_service.py @@ -44,13 +44,12 @@ class ApiKeyRepositoryService(ApiKeyRepositoryABC): return api_key def get_api_keys(self) -> List[ApiKey]: - api_keys = List(ApiKey) self._logger.trace(__name__, f"Send SQL command: {ApiKey.get_select_all_string()}") - results = self._context.select(ApiKey.get_select_all_string()) - for result in results: - api_keys.append(self._api_key_from_result(result)) - return api_keys + return List( + ApiKey, + [self._api_key_from_result(result) for result in self._context.select(ApiKey.get_select_all_string())], + ) def get_api_key(self, identifier: str, key: str) -> ApiKey: self._logger.trace(__name__, f"Send SQL command: {ApiKey.get_select_string(identifier, key)}") diff --git a/bot/src/bot_data/service/auth_user_repository_service.py b/bot/src/bot_data/service/auth_user_repository_service.py index 00afe7ae..70ebb786 100644 --- a/bot/src/bot_data/service/auth_user_repository_service.py +++ b/bot/src/bot_data/service/auth_user_repository_service.py @@ -64,23 +64,16 @@ class AuthUserRepositoryService(AuthUserRepositoryABC): __name__, f"Send SQL command: {auth_user.get_select_user_id_from_relations()}", ) - relation_ids = List(int) - results = self._context.select(auth_user.get_select_user_id_from_relations()) - for result in results: - self._logger.trace(__name__, f"Got auth user relation with id {result[0]}") - relation_ids.append(result[0]) - return relation_ids + return List(int, [result[0] for result in self._context.select(auth_user.get_select_user_id_from_relations())]) def get_all_auth_users(self) -> List[AuthUser]: - users = List(AuthUser) self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_all_string()}") - results = self._context.select(AuthUser.get_select_all_string()) - for result in results: - self._logger.trace(__name__, f"Get auth user with id {result[0]}") - users.append(self._user_from_result(result)) - return users + return List( + AuthUser, + [self._user_from_result(result) for result in self._context.select(AuthUser.get_select_all_string())], + ) def get_filtered_auth_users(self, criteria: AuthUserSelectCriteria) -> FilteredResult: users = self.get_all_auth_users() @@ -129,8 +122,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC): def get_auth_user_by_email(self, email: str) -> AuthUser: self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_by_email_string(email)}") - result = self._context.select(AuthUser.get_select_by_email_string(email))[0] - return self._user_from_result(result) + return self._user_from_result(self._context.select(AuthUser.get_select_by_email_string(email))[0]) def find_auth_user_by_email(self, email: str) -> Optional[AuthUser]: self._logger.trace(__name__, f"Send SQL command: {AuthUser.get_select_by_email_string(email)}") @@ -138,9 +130,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC): if result is None or len(result) == 0: return None - result = result[0] - - return self._user_from_result(result) + return self._user_from_result(result[0]) def find_auth_user_by_confirmation_id(self, id: str) -> Optional[AuthUser]: self._logger.trace( @@ -151,9 +141,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC): if result is None or len(result) == 0: return None - result = result[0] - - return self._user_from_result(result) + return self._user_from_result(result[0]) def find_auth_user_by_forgot_password_id(self, id: str) -> Optional[AuthUser]: self._logger.trace( @@ -164,9 +152,7 @@ class AuthUserRepositoryService(AuthUserRepositoryABC): if result is None or len(result) == 0: return None - result = result[0] - - return self._user_from_result(result) + return self._user_from_result(result[0]) def add_auth_user(self, user: AuthUser): self._logger.trace(__name__, f"Send SQL command: {user.insert_string}") diff --git a/bot/src/bot_data/service/auto_role_repository_service.py b/bot/src/bot_data/service/auto_role_repository_service.py index bf0d781a..323c4dc1 100644 --- a/bot/src/bot_data/service/auto_role_repository_service.py +++ b/bot/src/bot_data/service/auto_role_repository_service.py @@ -23,27 +23,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): AutoRoleRepositoryABC.__init__(self) - def get_auto_roles(self) -> List[AutoRole]: - auto_roles = List(AutoRole) - self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_all_string()}") - results = self._context.select(AutoRole.get_select_all_string()) - for result in results: - auto_roles.append( - AutoRole( - self._servers.get_server_by_id(result[1]), - result[2], - result[3], - result[4], - result[5], - id=result[0], - ) - ) - - return auto_roles - - def get_auto_role_by_id(self, id: int) -> AutoRole: - self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_by_id_string(id)}") - result = self._context.select(AutoRole.get_select_by_id_string(id))[0] + def _from_result(self, result: tuple) -> AutoRole: return AutoRole( self._servers.get_server_by_id(result[1]), result[2], @@ -53,55 +33,37 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): id=result[0], ) + def get_auto_roles(self) -> List[AutoRole]: + self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_all_string()}") + return List( + AutoRole, [self._from_result(result) for result in self._context.select(AutoRole.get_select_all_string())] + ) + + def get_auto_role_by_id(self, id: int) -> AutoRole: + self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_by_id_string(id)}") + return self._from_result(self._context.select(AutoRole.get_select_by_id_string(id))[0]) + def find_auto_role_by_id(self, id: int) -> Optional[AutoRole]: self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_by_id_string(id)}") result = self._context.select(AutoRole.get_select_by_id_string(id)) if result is None or len(result) == 0: return None - result = result[0] - - return AutoRole( - self._servers.get_server_by_id(result[1]), - result[2], - result[3], - result[4], - result[5], - id=result[0], - ) + return self._from_result(result[0]) def get_auto_roles_by_server_id(self, id: int) -> List[AutoRole]: self._logger.trace(__name__, f"Send SQL command: {AutoRole.get_select_by_server_id_string(id)}") - auto_roles = List(AutoRole) - results = self._context.select(AutoRole.get_select_by_server_id_string(id)) - for result in results: - auto_roles.append( - AutoRole( - self._servers.get_server_by_id(result[1]), - result[2], - result[3], - result[4], - result[5], - id=result[0], - ) - ) - - return auto_roles + return List( + AutoRole, + [self._from_result(result) for result in self._context.select(AutoRole.get_select_by_server_id_string(id))], + ) def get_auto_role_by_message_id(self, id: int) -> AutoRole: self._logger.trace( __name__, f"Send SQL command: {AutoRole.get_select_by_message_id_string(id)}", ) - result = self._context.select(AutoRole.get_select_by_message_id_string(id))[0] - return AutoRole( - self._servers.get_server_by_id(result[1]), - result[2], - result[3], - result[4], - result[5], - id=result[0], - ) + return self._from_result(self._context.select(AutoRole.get_select_by_message_id_string(id))[0]) def find_auto_role_by_message_id(self, id: int) -> Optional[AutoRole]: self._logger.trace( @@ -112,16 +74,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): if result is None or len(result) == 0: return None - result = result[0] - - return AutoRole( - self._servers.get_server_by_id(result[1]), - result[2], - result[3], - result[4], - result[5], - id=result[0], - ) + return self._from_result(result[0]) def add_auto_role(self, auto_role: AutoRole): self._logger.trace(__name__, f"Send SQL command: {auto_role.insert_string}") @@ -135,27 +88,7 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): self._logger.trace(__name__, f"Send SQL command: {auto_role.delete_string}") self._context.cursor.execute(auto_role.delete_string) - def get_auto_role_rules(self) -> List[AutoRoleRule]: - auto_role_rules = List(AutoRoleRule) - self._logger.trace(__name__, f"Send SQL command: {AutoRoleRule.get_select_all_string()}") - results = self._context.select(AutoRoleRule.get_select_all_string()) - for result in results: - auto_role_rules.append( - AutoRoleRule( - self.get_auto_role_by_id(result[1]), - result[2], - result[3], - result[4], - result[5], - id=result[0], - ) - ) - - return auto_role_rules - - def get_auto_role_rule_by_id(self, id: int) -> AutoRoleRule: - self._logger.trace(__name__, f"Send SQL command: {AutoRoleRule.get_select_by_id_string(id)}") - result = self._context.select(AutoRoleRule.get_select_by_id_string(id))[0] + def _rule_from_result(self, result: tuple) -> AutoRoleRule: return AutoRoleRule( self.get_auto_role_by_id(result[1]), result[2], @@ -165,26 +98,29 @@ class AutoRoleRepositoryService(AutoRoleRepositoryABC): id=result[0], ) + def get_auto_role_rules(self) -> List[AutoRoleRule]: + self._logger.trace(__name__, f"Send SQL command: {AutoRoleRule.get_select_all_string()}") + return List( + AutoRoleRule, + [self._rule_from_result(result) for result in self._context.select(AutoRoleRule.get_select_all_string())], + ) + + def get_auto_role_rule_by_id(self, id: int) -> AutoRoleRule: + self._logger.trace(__name__, f"Send SQL command: {AutoRoleRule.get_select_by_id_string(id)}") + return self._rule_from_result(self._context.select(AutoRoleRule.get_select_by_id_string(id))[0]) + def get_auto_role_rules_by_auto_role_id(self, id: int) -> List[AutoRoleRule]: - auto_role_rules = List(AutoRoleRule) self._logger.trace( __name__, f"Send SQL command: {AutoRoleRule.get_select_by_auto_role_id_string(id)}", ) - results = self._context.select(AutoRoleRule.get_select_by_auto_role_id_string(id)) - for result in results: - auto_role_rules.append( - AutoRoleRule( - self.get_auto_role_by_id(result[1]), - result[2], - result[3], - result[4], - result[5], - id=result[0], - ) - ) - - return auto_role_rules + return List( + AutoRoleRule, + [ + self._rule_from_result(result) + for result in self._context.select(AutoRoleRule.get_select_by_auto_role_id_string(id)) + ], + ) def add_auto_role_rule(self, auto_role_rule: AutoRoleRule): self._logger.trace(__name__, f"Send SQL command: {auto_role_rule.insert_string}") diff --git a/bot/src/bot_data/service/client_repository_service.py b/bot/src/bot_data/service/client_repository_service.py index e3d08ad3..ba877c1c 100644 --- a/bot/src/bot_data/service/client_repository_service.py +++ b/bot/src/bot_data/service/client_repository_service.py @@ -23,32 +23,7 @@ class ClientRepositoryService(ClientRepositoryABC): ClientRepositoryABC.__init__(self) - def get_clients(self) -> List[Client]: - clients = List(Client) - self._logger.trace(__name__, f"Send SQL command: {Client.get_select_all_string()}") - results = self._context.select(Client.get_select_all_string()) - for result in results: - self._logger.trace(__name__, f"Get client with id {result[0]}") - clients.append( - Client( - result[1], - result[2], - result[3], - result[4], - result[5], - result[6], - self._servers.get_server_by_id(result[7]), - result[8], - result[9], - id=result[0], - ) - ) - - return clients - - def get_client_by_id(self, client_id: int) -> Client: - self._logger.trace(__name__, f"Send SQL command: {Client.get_select_by_id_string(client_id)}") - result = self._context.select(Client.get_select_by_id_string(client_id)) + def _from_result(self, result: tuple) -> Client: return Client( result[1], result[2], @@ -62,49 +37,37 @@ class ClientRepositoryService(ClientRepositoryABC): id=result[0], ) + def get_clients(self) -> List[Client]: + self._logger.trace(__name__, f"Send SQL command: {Client.get_select_all_string()}") + + return List( + Client, [self._from_result(result) for result in self._context.select(Client.get_select_all_string())] + ) + + def get_client_by_id(self, client_id: int) -> Client: + self._logger.trace(__name__, f"Send SQL command: {Client.get_select_by_id_string(client_id)}") + return self._from_result(self._context.select(Client.get_select_by_id_string(client_id))[0]) + def get_clients_by_server_id(self, server_id: int) -> List[Client]: - clients = List(Client) self._logger.trace( __name__, f"Send SQL command: {Client.get_select_by_server_id_string(server_id)}", ) - results = self._context.select(Client.get_select_by_server_id_string(server_id)) - for result in results: - clients.append( - Client( - result[1], - result[2], - result[3], - result[4], - result[5], - result[6], - self._servers.get_server_by_id(result[7]), - result[8], - result[9], - id=result[0], - ) - ) - return clients + return List( + Client, + [ + self._from_result(result) + for result in self._context.select(Client.get_select_by_server_id_string(server_id)) + ], + ) def get_client_by_discord_id(self, discord_id: int) -> Client: self._logger.trace( __name__, f"Send SQL command: {Client.get_select_by_discord_id_string(discord_id)}", ) - result = self._context.select(Client.get_select_by_discord_id_string(discord_id))[0] - return Client( - result[1], - result[2], - result[3], - result[4], - result[5], - result[6], - self._servers.get_server_by_id(result[7]), - result[8], - result[9], - id=result[0], - ) + return self._from_result(self._context.select(Client.get_select_by_discord_id_string(discord_id))[0]) def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]: self._logger.trace( @@ -115,20 +78,7 @@ class ClientRepositoryService(ClientRepositoryABC): if result is None or len(result) == 0: return None - result = result[0] - - return Client( - result[1], - result[2], - result[3], - result[4], - result[5], - result[6], - self._servers.get_server_by_id(result[7]), - result[8], - result[9], - id=result[0], - ) + return self._from_result(result[0]) def find_client_by_server_id(self, discord_id: int) -> Optional[Client]: self._logger.trace( @@ -139,20 +89,7 @@ class ClientRepositoryService(ClientRepositoryABC): if result is None or len(result) == 0: return None - result = result[0] - - return Client( - result[1], - result[2], - result[3], - result[4], - result[5], - result[6], - self._servers.get_server_by_id(result[7]), - result[8], - result[9], - id=result[0], - ) + return self._from_result(result[0]) def find_client_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[Client]: self._logger.trace( @@ -163,20 +100,7 @@ class ClientRepositoryService(ClientRepositoryABC): if result is None or len(result) == 0: return None - result = result[0] - - return Client( - result[1], - result[2], - result[3], - result[4], - result[5], - result[6], - self._servers.get_server_by_id(result[7]), - result[8], - result[9], - id=result[0], - ) + return self._from_result(result[0]) def add_client(self, client: Client): self._logger.trace(__name__, f"Send SQL command: {client.insert_string}") diff --git a/bot/src/bot_data/service/game_server_repository_service.py b/bot/src/bot_data/service/game_server_repository_service.py index 1bdd0aeb..1b9775a5 100644 --- a/bot/src/bot_data/service/game_server_repository_service.py +++ b/bot/src/bot_data/service/game_server_repository_service.py @@ -35,49 +35,49 @@ class GameServerRepositoryService(GameServerRepositoryABC): ) def get_game_servers(self) -> List[GameServer]: - game_servers = List(GameServer) self._logger.trace( __name__, f"Send SQL command: {GameServer.get_select_all_string()}", ) - results = self._context.select(GameServer.get_select_all_string()) - for result in results: - self._logger.trace(__name__, f"Get user-joined-game-server with id {result[0]}") - game_servers.append(self._from_result(result)) - return game_servers + return List( + GameServer, + [self._from_result(result) for result in self._context.select(GameServer.get_select_all_string())], + ) def get_game_servers_by_server_id(self, id: int) -> List[GameServer]: - game_servers = List(GameServer) self._logger.trace( __name__, f"Send SQL command: {GameServer.get_select_by_server_id_string(id)}", ) - results = self._context.select(GameServer.get_select_by_server_id_string(id)) - for result in results: - self._logger.trace(__name__, f"Get user-joined-game-server with id {result[0]}") - game_servers.append(self._from_result(result)) - return game_servers + return List( + GameServer, + [ + self._from_result(result) + for result in self._context.select(GameServer.get_select_by_server_id_string(id)) + ], + ) def get_game_server_by_id(self, id: int) -> GameServer: self._logger.trace( __name__, f"Send SQL command: {GameServer.get_select_by_id_string(id)}", ) - result = self._context.select(GameServer.get_select_by_id_string(id))[0] - return self._from_result(result) + return self._from_result(self._context.select(GameServer.get_select_by_id_string(id))[0]) def get_game_servers_by_api_key_id(self, id: int) -> List[GameServer]: self._logger.trace( __name__, f"Send SQL command: {GameServer.get_select_by_api_key_id_string(id)}", ) - game_servers = List(GameServer) - results = self._context.select(GameServer.get_select_by_api_key_id_string(id)) - for result in results: - game_servers.append(self._from_result(result)) - return game_servers + return List( + GameServer, + [ + self._from_result(result) + for result in self._context.select(GameServer.get_select_by_api_key_id_string(id)) + ], + ) def add_game_server(self, game_server: GameServer): self._logger.trace(__name__, f"Send SQL command: {game_server.insert_string}") diff --git a/bot/src/bot_data/service/level_repository_service.py b/bot/src/bot_data/service/level_repository_service.py index c713c0da..6897ddcc 100644 --- a/bot/src/bot_data/service/level_repository_service.py +++ b/bot/src/bot_data/service/level_repository_service.py @@ -4,8 +4,8 @@ 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.server_repository_abc import ServerRepositoryABC from bot_data.abc.level_repository_abc import LevelRepositoryABC +from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.model.level import Level @@ -41,20 +41,15 @@ class LevelRepositoryService(LevelRepositoryABC): ) def get_levels(self) -> List[Level]: - levels = List(Level) self._logger.trace(__name__, f"Send SQL command: {Level.get_select_all_string()}") - results = self._context.select(Level.get_select_all_string()) - for result in results: - self._logger.trace(__name__, f"Get level with id {result[0]}") - levels.append(self._level_from_result(result)) - - return levels + return List( + Level, [self._level_from_result(result) for result in self._context.select(Level.get_select_all_string())] + ) def get_level_by_id(self, id: int) -> Level: self._logger.trace(__name__, f"Send SQL command: {Level.get_select_by_id_string(id)}") - result = self._context.select(Level.get_select_by_id_string(id))[0] - return self._level_from_result(result) + return self._level_from_result(self._context.select(Level.get_select_by_id_string(id))[0]) def find_level_by_id(self, id: int) -> Optional[Level]: self._logger.trace(__name__, f"Send SQL command: {Level.get_select_by_id_string(id)}") @@ -65,21 +60,19 @@ class LevelRepositoryService(LevelRepositoryABC): return self._level_from_result(result[0]) def get_levels_by_server_id(self, server_id: int) -> List[Level]: - levels = List(Level) self._logger.trace( __name__, f"Send SQL command: {Level.get_select_by_server_id_string(server_id)}", ) - results = self._context.select(Level.get_select_by_server_id_string(server_id)) - - for result in results: - self._logger.trace(__name__, f"Get level with id {result[0]}") - levels.append(self._level_from_result(result)) - - return levels + return List( + Level, + [ + self._level_from_result(result) + for result in self._context.select(Level.get_select_by_server_id_string(server_id)) + ], + ) def find_levels_by_server_id(self, server_id: int) -> Optional[List[Level]]: - levels = List(Level) self._logger.trace( __name__, f"Send SQL command: {Level.get_select_by_server_id_string(server_id)}", @@ -88,11 +81,10 @@ class LevelRepositoryService(LevelRepositoryABC): if results is None or len(results) == 0: return None - for result in results: - self._logger.trace(__name__, f"Get level with id {result[0]}") - levels.append(self._level_from_result(result)) - - return levels + return List( + Level, + [self._level_from_result(result) for result in results], + ) def add_level(self, level: Level): self._logger.trace(__name__, f"Send SQL command: {level.insert_string}") diff --git a/bot/src/bot_data/service/scheduled_event_repository_service.py b/bot/src/bot_data/service/scheduled_event_repository_service.py index dc394fdf..d8e9039f 100644 --- a/bot/src/bot_data/service/scheduled_event_repository_service.py +++ b/bot/src/bot_data/service/scheduled_event_repository_service.py @@ -5,8 +5,8 @@ from cpl_query.extension import List from discord import EntityType from bot_core.logging.database_logger import DatabaseLogger -from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.abc.scheduled_event_repository_abc import ScheduledEventRepositoryABC +from bot_data.abc.server_repository_abc import ServerRepositoryABC from bot_data.model.scheduled_event import ScheduledEvent from bot_data.model.scheduled_event_interval_enum import ScheduledEventIntervalEnum @@ -49,34 +49,34 @@ class ScheduledEventRepositoryService(ScheduledEventRepositoryABC): ) def get_scheduled_events(self) -> List[ScheduledEvent]: - scheduled_events = List(ScheduledEvent) self._logger.trace(__name__, f"Send SQL command: {ScheduledEvent.get_select_all_string()}") - results = self._context.select(ScheduledEvent.get_select_all_string()) - for result in results: - self._logger.trace(__name__, f"Get scheduled_event with id {result[0]}") - scheduled_events.append(self._scheduled_event_from_result(result)) - return scheduled_events + return List( + ScheduledEvent, + [ + self._scheduled_event_from_result(result) + for result in self._context.select(ScheduledEvent.get_select_all_string()) + ], + ) def get_scheduled_event_by_id(self, id: int) -> ScheduledEvent: self._logger.trace(__name__, f"Send SQL command: {ScheduledEvent.get_select_by_id_string(id)}") - result = self._context.select(ScheduledEvent.get_select_by_id_string(id))[0] - return self._scheduled_event_from_result(result) + return self._scheduled_event_from_result(self._context.select(ScheduledEvent.get_select_by_id_string(id))[0]) def get_scheduled_events_by_server_id(self, server_id: int) -> List[ScheduledEvent]: - scheduled_events = List(ScheduledEvent) self._logger.trace( __name__, f"Send SQL command: {ScheduledEvent.get_select_by_server_id_string(server_id)}", ) - results = self._context.select(ScheduledEvent.get_select_by_server_id_string(server_id)) - for result in results: - self._logger.trace(__name__, f"Get scheduled_event with id {result[0]}") - scheduled_events.append(self._scheduled_event_from_result(result)) - - return scheduled_events + return List( + ScheduledEvent, + [ + self._scheduled_event_from_result(result) + for result in self._context.select(ScheduledEvent.get_select_by_server_id_string(server_id)) + ], + ) def add_scheduled_event(self, scheduled_event: ScheduledEvent): self._logger.trace(__name__, f"Send SQL command: {scheduled_event.insert_string}")