From 8e3c8459f823fa15e541593e13d56459e2287cea Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 25 Sep 2023 18:06:58 +0200 Subject: [PATCH] Fixed user joined game server mutation #364 --- .../src/bot_data/abc/game_server_repository_abc.py | 2 +- .../service/game_server_repository_service.py | 9 ++++++--- .../mutations/user_joined_game_server_mutation.py | 13 +------------ 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/kdb-bot/src/bot_data/abc/game_server_repository_abc.py b/kdb-bot/src/bot_data/abc/game_server_repository_abc.py index 50e6fe7a..b71d1582 100644 --- a/kdb-bot/src/bot_data/abc/game_server_repository_abc.py +++ b/kdb-bot/src/bot_data/abc/game_server_repository_abc.py @@ -23,7 +23,7 @@ class GameServerRepositoryABC(ABC): pass @abstractmethod - def get_game_server_by_api_key_id(self, id: int) -> GameServer: + def get_game_servers_by_api_key_id(self, id: int) -> List[GameServer]: pass @abstractmethod diff --git a/kdb-bot/src/bot_data/service/game_server_repository_service.py b/kdb-bot/src/bot_data/service/game_server_repository_service.py index 20f89433..1bdd0aeb 100644 --- a/kdb-bot/src/bot_data/service/game_server_repository_service.py +++ b/kdb-bot/src/bot_data/service/game_server_repository_service.py @@ -68,13 +68,16 @@ class GameServerRepositoryService(GameServerRepositoryABC): result = self._context.select(GameServer.get_select_by_id_string(id))[0] return self._from_result(result) - def get_game_server_by_api_key_id(self, id: int) -> GameServer: + 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)}", ) - result = self._context.select(GameServer.get_select_by_api_key_id_string(id))[0] - return self._from_result(result) + 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 def add_game_server(self, game_server: GameServer): self._logger.trace(__name__, f"Send SQL command: {game_server.insert_string}") diff --git a/kdb-bot/src/bot_graphql/mutations/user_joined_game_server_mutation.py b/kdb-bot/src/bot_graphql/mutations/user_joined_game_server_mutation.py index 62fef010..957b3a86 100644 --- a/kdb-bot/src/bot_graphql/mutations/user_joined_game_server_mutation.py +++ b/kdb-bot/src/bot_graphql/mutations/user_joined_game_server_mutation.py @@ -75,12 +75,6 @@ class UserJoinedGameServerMutation(QueryABC): ) def resolve_user_joined(self, *_, input: dict): - api_key = self._get_api_key() - if api_key is None: - self._logger.warn(__name__, f"UserJoinedGameServer not saved. Api-Key not available!") - return - - game_server = self._game_servers.get_game_server_by_api_key_id(api_key.id) game_ident = self._user_game_idents.get_user_game_ident_by_ident(input["ident"]) user = game_ident.user self._can_user_mutate_data(user.server, UserRoleEnum.admin) @@ -93,18 +87,13 @@ class UserJoinedGameServerMutation(QueryABC): ) return - new = UserJoinedGameServer(user, game_server, datetime.now()) + new = UserJoinedGameServer(user, game_ident.game_server, datetime.now()) self._user_joined_game_servers.add_user_joined_game_server(new) self._db.save_changes() return self._user_joined_game_servers.get_active_user_joined_game_server_by_user_id(user.id) def resolve_user_left(self, *_, input: dict): - api_key = self._get_api_key() - if api_key is None: - self._logger.warn(__name__, f"UserJoinedGameServer not saved. Api-Key not available!") - return - game_ident = self._user_game_idents.find_user_game_ident_by_ident(input["ident"]) if game_ident is None: return