Added graphql from prototype #162
This commit is contained in:
@@ -28,19 +28,21 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
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]
|
||||
))
|
||||
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
|
||||
|
||||
@@ -57,7 +59,7 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def get_client_by_discord_id(self, discord_id: int) -> Client:
|
||||
@@ -76,7 +78,7 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]:
|
||||
@@ -87,9 +89,9 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result = self._context.select(Client.get_select_by_discord_id_string(discord_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return Client(
|
||||
result[1],
|
||||
result[2],
|
||||
@@ -100,7 +102,7 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_client_by_server_id(self, discord_id: int) -> Optional[Client]:
|
||||
@@ -111,9 +113,9 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result = self._context.select(Client.get_select_by_server_id_string(discord_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return Client(
|
||||
result[1],
|
||||
result[2],
|
||||
@@ -124,7 +126,7 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def find_client_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[Client]:
|
||||
@@ -135,9 +137,9 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
result = self._context.select(Client.get_select_by_discord_id_and_server_id_string(discord_id, server_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
|
||||
return Client(
|
||||
result[1],
|
||||
result[2],
|
||||
@@ -148,7 +150,7 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
self._servers.get_server_by_id(result[7]),
|
||||
result[8],
|
||||
result[9],
|
||||
id=result[0]
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def add_client(self, client: Client):
|
||||
@@ -166,14 +168,14 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
def _get_client_and_server(self, id: int, server_id: int) -> Client:
|
||||
server = self._servers.find_server_by_discord_id(server_id)
|
||||
if server is None:
|
||||
self._logger.warn(__name__, f'Cannot find server by id {server_id}')
|
||||
raise Exception('Value not found')
|
||||
|
||||
self._logger.warn(__name__, f"Cannot find server by id {server_id}")
|
||||
raise Exception("Value not found")
|
||||
|
||||
client = self.find_client_by_discord_id_and_server_id(id, server.server_id)
|
||||
if client is None:
|
||||
self._logger.warn(__name__, f'Cannot find client by ids {id}@{server.server_id}')
|
||||
raise Exception('Value not found')
|
||||
|
||||
self._logger.warn(__name__, f"Cannot find client by ids {id}@{server.server_id}")
|
||||
raise Exception("Value not found")
|
||||
|
||||
return client
|
||||
|
||||
def append_sent_message_count(self, client_id: int, server_id: int, value: int):
|
||||
|
@@ -22,12 +22,7 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
self._logger.trace(__name__, f"Send SQL command: {Server.get_select_all_string()}")
|
||||
results = self._context.select(Server.get_select_all_string())
|
||||
for result in results:
|
||||
servers.append(Server(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
))
|
||||
servers.append(Server(result[1], result[2], result[3], id=result[0]))
|
||||
|
||||
return servers
|
||||
|
||||
@@ -59,12 +54,7 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
def get_server_by_id(self, server_id: int) -> Server:
|
||||
self._logger.trace(__name__, f"Send SQL command: {Server.get_select_by_id_string(server_id)}")
|
||||
result = self._context.select(Server.get_select_by_id_string(server_id))[0]
|
||||
return Server(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
)
|
||||
return Server(result[1], result[2], result[3], id=result[0])
|
||||
|
||||
def get_server_by_discord_id(self, discord_id: int) -> Server:
|
||||
self._logger.trace(
|
||||
@@ -72,12 +62,7 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
f"Send SQL command: {Server.get_select_by_discord_id_string(discord_id)}",
|
||||
)
|
||||
result = self._context.select(Server.get_select_by_discord_id_string(discord_id))[0]
|
||||
return Server(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
)
|
||||
return Server(result[1], result[2], result[3], id=result[0])
|
||||
|
||||
def find_server_by_discord_id(self, discord_id: int) -> Optional[Server]:
|
||||
self._logger.trace(
|
||||
@@ -87,15 +72,10 @@ class ServerRepositoryService(ServerRepositoryABC):
|
||||
result = self._context.select(Server.get_select_by_discord_id_string(discord_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
||||
result = result[0]
|
||||
|
||||
return Server(
|
||||
result[1],
|
||||
result[2],
|
||||
result[3],
|
||||
id=result[0]
|
||||
)
|
||||
return Server(result[1], result[2], result[3], id=result[0])
|
||||
|
||||
def add_server(self, server: Server):
|
||||
self._logger.trace(__name__, f"Send SQL command: {server.insert_string}")
|
||||
|
Reference in New Issue
Block a user