Added helper functions to append client values

This commit is contained in:
Sven Heidemann 2021-12-08 07:41:09 +01:00
parent e34fbb60aa
commit be5567c1fd
2 changed files with 36 additions and 2 deletions

View File

@ -37,5 +37,17 @@ class ClientRepositoryABC(ABC):
@abstractmethod @abstractmethod
def delete_client(self, client: Client): pass def delete_client(self, client: Client): pass
@abstractmethod
def apppend_sent_message_count(self, id: int, server_id: int, value: int): pass
@abstractmethod @abstractmethod
def apppend_received_message_count(self, id: int, server_id: int, value: int): pass def apppend_received_message_count(self, id: int, server_id: int, value: int): pass
@abstractmethod
def apppend_deleted_message_count(self, id: int, server_id: int, value: int): pass
@abstractmethod
def apppend_received_command_count(self, id: int, server_id: int, value: int): pass
@abstractmethod
def apppend_moved_users_count(self, id: int, server_id: int, value: int): pass

View File

@ -134,7 +134,7 @@ class ClientRepositoryService(ClientRepositoryABC):
self._logger.trace(__name__, f'Send SQL command: {client.delete_string}') self._logger.trace(__name__, f'Send SQL command: {client.delete_string}')
self._context.cursor.execute(client.delete_string) self._context.cursor.execute(client.delete_string)
def apppend_received_message_count(self, id: int, server_id: int, value: int): def _get_client_and_server(self, id: int, server_id: int) -> Client:
server = self._servers.find_server_by_discord_id(server_id) server = self._servers.find_server_by_discord_id(server_id)
if server is None: if server is None:
self._logger.warn(__name__, f'Cannot find server by id {server_id}') self._logger.warn(__name__, f'Cannot find server by id {server_id}')
@ -145,5 +145,27 @@ class ClientRepositoryService(ClientRepositoryABC):
self._logger.warn(__name__, f'Cannot find client by ids {id}@{server.server_id}') self._logger.warn(__name__, f'Cannot find client by ids {id}@{server.server_id}')
raise Exception('Value not found') raise Exception('Value not found')
client.received_message_count += 1 def apppend_sent_message_count(self, id: int, server_id: int, value: int):
client = self._get_client_and_server(id, server_id)
client.sent_message_count += value
self.update_client(client)
def apppend_received_message_count(self, id: int, server_id: int, value: int):
client = self._get_client_and_server(id, server_id)
client.received_message_count += value
self.update_client(client)
def apppend_deleted_message_count(self, id: int, server_id: int, value: int):
client = self._get_client_and_server(id, server_id)
client.deleted_message_count += value
self.update_client(client)
def apppend_received_command_count(self, id: int, server_id: int, value: int):
client = self._get_client_and_server(id, server_id)
client.received_command_count += value
self.update_client(client)
def apppend_moved_users_count(self, id: int, server_id: int, value: int):
client = self._get_client_and_server(id, server_id)
client.moved_users_count += value
self.update_client(client) self.update_client(client)