A-0.3 - Basismodul #36
@ -23,7 +23,10 @@ class ClientRepositoryABC(ABC):
|
|||||||
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]: pass
|
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]: pass
|
||||||
|
|
||||||
@abstractmethod
|
@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
|
@abstractmethod
|
||||||
def add_client(self, client: Client): pass
|
def add_client(self, client: Client): pass
|
||||||
|
@ -90,6 +90,14 @@ class Client(TableABC):
|
|||||||
WHERE `ServerId` = {id};
|
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
|
@property
|
||||||
def insert_string(self) -> str:
|
def insert_string(self) -> str:
|
||||||
return str(f"""
|
return str(f"""
|
||||||
|
@ -103,6 +103,25 @@ class ClientRepositoryService(ClientRepositoryABC):
|
|||||||
id=result[0]
|
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):
|
def add_client(self, client: Client):
|
||||||
self._logger.trace(__name__, f'Send SQL command: {client.insert_string}')
|
self._logger.trace(__name__, f'Send SQL command: {client.insert_string}')
|
||||||
self._context.cursor.execute(client.insert_string)
|
self._context.cursor.execute(client.insert_string)
|
||||||
|
Reference in New Issue
Block a user