A-0.3 - Basismodul #36
@ -18,10 +18,13 @@ class UserRepositoryABC(ABC):
|
||||
def get_user_by_id(self, id: int) -> User: pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_discord_id(self, discord_id: int) -> User: pass
|
||||
def get_users_by_discord_id(self, discord_id: int) -> List[User]: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_by_discord_id(self, discord_id: int) -> Optional[User]: pass
|
||||
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User: pass
|
||||
|
||||
@abstractmethod
|
||||
def find_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[User]: pass
|
||||
|
||||
@abstractmethod
|
||||
def add_user(self, user: User): pass
|
||||
|
@ -58,6 +58,14 @@ class User(TableABC):
|
||||
WHERE `DiscordId` = {id};
|
||||
""")
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_and_server_id_string(dc_id: int, s_id: int) -> str:
|
||||
return str(f"""
|
||||
SELECT * FROM `Users`
|
||||
WHERE `DiscordId` = {dc_id}
|
||||
AND `ServerId` = {s_id};
|
||||
""")
|
||||
|
||||
@property
|
||||
def insert_string(self) -> str:
|
||||
return str(f"""
|
||||
|
@ -43,10 +43,22 @@ class UserRepositoryService(UserRepositoryABC):
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
def get_user_by_discord_id(self, discord_id: int) -> User:
|
||||
|
||||
def get_users_by_discord_id(self, discord_id: int) -> List[User]:
|
||||
users = List(User)
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_string(discord_id)}')
|
||||
result = self._context.select(User.get_select_by_discord_id_string(discord_id))[0]
|
||||
results = self._context.select(User.get_select_by_discord_id_string(discord_id))
|
||||
for result in results:
|
||||
users.append(User(
|
||||
result[1],
|
||||
result[2],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0]
|
||||
))
|
||||
|
||||
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User:
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}')
|
||||
result = self._context.select(User.get_select_by_discord_id_and_server_id_string(discord_id, server_id))[0]
|
||||
|
||||
return User(
|
||||
result[1],
|
||||
@ -55,9 +67,9 @@ class UserRepositoryService(UserRepositoryABC):
|
||||
id=result[0]
|
||||
)
|
||||
|
||||
def find_user_by_discord_id(self, discord_id: int) -> Optional[User]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_string(discord_id)}')
|
||||
result = self._context.select(User.get_select_by_discord_id_string(discord_id))
|
||||
def find_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> Optional[User]:
|
||||
self._logger.trace(__name__, f'Send SQL command: {User.get_select_by_discord_id_and_server_id_string(discord_id, server_id)}')
|
||||
result = self._context.select(User.get_select_by_discord_id_and_server_id_string(discord_id, server_id))
|
||||
if result is None or len(result) == 0:
|
||||
return None
|
||||
|
||||
|
Reference in New Issue
Block a user