Added find function to client repo
This commit is contained in:
		| @@ -23,7 +23,10 @@ class ClientRepositoryABC(ABC): | ||||
|     def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]: pass | ||||
|      | ||||
|     @abstractmethod | ||||
|     def find_client_by_server_id(self, discord_id: int) -> Optional[Client]: pass | ||||
|     def find_client_by_server_id(self, server_id: int) -> Optional[Client]: pass | ||||
|      | ||||
|     @abstractmethod | ||||
|     def find_client_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[Client]: pass | ||||
|      | ||||
|     @abstractmethod | ||||
|     def add_client(self, client: Client): pass | ||||
|   | ||||
| @@ -90,6 +90,14 @@ class Client(TableABC): | ||||
|             WHERE `ServerId` = {id}; | ||||
|         """) | ||||
|  | ||||
|     @staticmethod | ||||
|     def get_select_by_discord_id_and_server_id_string(id: int, server_id: int) -> str: | ||||
|         return str(f""" | ||||
|             SELECT * FROM `Clients` | ||||
|             WHERE `DiscordClientId` = {id} | ||||
|             AND `ServerId` = {server_id}; | ||||
|         """) | ||||
|  | ||||
|     @property | ||||
|     def insert_string(self) -> str: | ||||
|         return str(f""" | ||||
|   | ||||
| @@ -102,6 +102,25 @@ class ClientRepositoryService(ClientRepositoryABC): | ||||
|             self._servers.get_server_by_id(result[7]), | ||||
|             id=result[0] | ||||
|         ) | ||||
|  | ||||
|     def find_client_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[Client]: | ||||
|         self._logger.trace(__name__, f'Send SQL command: {Client.get_select_by_server_id_string(discord_id)}') | ||||
|         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], | ||||
|             result[3], | ||||
|             result[4], | ||||
|             result[5], | ||||
|             result[6], | ||||
|             self._servers.get_server_by_id(result[7]), | ||||
|             id=result[0] | ||||
|         ) | ||||
|      | ||||
|     def add_client(self, client: Client): | ||||
|         self._logger.trace(__name__, f'Send SQL command: {client.insert_string}') | ||||
|   | ||||
		Reference in New Issue
	
	Block a user