Added more queries #162
This commit is contained in:
@@ -2,6 +2,7 @@ from abc import ABC, abstractmethod
|
||||
from typing import Optional
|
||||
|
||||
from cpl_query.extension import List
|
||||
|
||||
from bot_data.model.client import Client
|
||||
|
||||
|
||||
@@ -22,6 +23,10 @@ class ClientRepositoryABC(ABC):
|
||||
def get_client_by_discord_id(self, discord_id: int) -> Client:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_clients_by_server_id(self, server_id: int) -> List[Client]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def find_client_by_discord_id(self, discord_id: int) -> Optional[Client]:
|
||||
pass
|
||||
|
@@ -27,6 +27,10 @@ class UserRepositoryABC(ABC):
|
||||
def get_users_by_discord_id(self, discord_id: int) -> List[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_users_by_server_id(self, server_id: int) -> List[User]:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User:
|
||||
pass
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from datetime import datetime
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.database import TableABC
|
||||
|
||||
from bot_data.model.server import Server
|
||||
@@ -62,6 +63,15 @@ class User(TableABC):
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_server_id_string(server_id: int) -> str:
|
||||
return str(
|
||||
f"""
|
||||
SELECT * FROM `Users`
|
||||
WHERE `ServerId` = {server_id};
|
||||
"""
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def get_select_by_discord_id_string(id: int) -> str:
|
||||
return str(
|
||||
|
@@ -62,6 +62,28 @@ class ClientRepositoryService(ClientRepositoryABC):
|
||||
id=result[0],
|
||||
)
|
||||
|
||||
def get_clients_by_server_id(self, server_id: int) -> List[Client]:
|
||||
clients = List(Client)
|
||||
self._logger.trace(__name__, f"Send SQL command: {Client.get_select_by_server_id_string(server_id)}")
|
||||
results = self._context.select(Client.get_select_by_server_id_string(server_id))
|
||||
for result in results:
|
||||
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
|
||||
|
||||
def get_client_by_discord_id(self, discord_id: int) -> Client:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
|
@@ -85,6 +85,25 @@ class UserRepositoryService(UserRepositoryABC):
|
||||
|
||||
return users
|
||||
|
||||
def get_users_by_server_id(self, server_id: int) -> List[User]:
|
||||
users = List(User)
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
f"Send SQL command: {User.get_select_by_server_id_string(server_id)}",
|
||||
)
|
||||
results = self._context.select(User.get_select_by_server_id_string(server_id))
|
||||
for result in results:
|
||||
users.append(
|
||||
User(
|
||||
result[1],
|
||||
result[2],
|
||||
self._servers.get_server_by_id(result[3]),
|
||||
id=result[0],
|
||||
)
|
||||
)
|
||||
|
||||
return users
|
||||
|
||||
def get_user_by_discord_id_and_server_id(self, discord_id: int, server_id: int) -> User:
|
||||
self._logger.trace(
|
||||
__name__,
|
||||
|
Reference in New Issue
Block a user