Fixed user joined game server mutation #364

This commit is contained in:
Sven Heidemann 2023-09-25 18:06:58 +02:00
parent 481c0f881a
commit 8e3c8459f8
3 changed files with 8 additions and 16 deletions

View File

@ -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

View File

@ -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}")

View File

@ -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